Prevent HTMX from messing up the initial state
Django CI/CD / build-and-push (push) Successful in 1m15s Details

This commit is contained in:
Lukáš Kucharczyk 2023-11-16 20:33:56 +01:00
parent b7e14ecc83
commit 206b5f6d46
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
}
}
});