From 206b5f6d46732726a1f9997ea74fb26a5efc3e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 16 Nov 2023 20:33:56 +0100 Subject: [PATCH] Prevent HTMX from messing up the initial state --- games/static/js/add_purchase.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/games/static/js/add_purchase.js b/games/static/js/add_purchase.js index d593e48..cfacecc 100644 --- a/games/static/js/add_purchase.js +++ b/games/static/js/add_purchase.js @@ -29,3 +29,15 @@ document.addEventListener("htmx:afterSwap", setupElementHandlers); getEl("#id_type").onchange = () => { 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 + } + } +});