Prevent HTMX from messing up the initial state

This commit is contained in:
Lukáš Kucharczyk 2023-11-16 20:33:56 +01:00
parent a32d6c38ab
commit 0f5067d66d
1 changed files with 12 additions and 0 deletions

View File

@ -29,3 +29,15 @@ document.addEventListener("htmx:afterSwap", setupElementHandlers);
getEl("#id_type").onchange = () => { getEl("#id_type").onchange = () => {
setupElementHandlers(); setupElementHandlers();
}; };
document.body.addEventListener('htmx:beforeRequest', function(event) {
// Assuming 'Purchase1' is the element that triggers the HTMX request
if (event.target.id === 'id_edition') {
var idEditionValue = document.getElementById('id_edition').value;
// Condition to check - replace this with your actual logic
if (idEditionValue != '') {
event.preventDefault(); // This cancels the HTMX request
}
}
});