From a698f96bbc6b675ac6e6034a948b576d693e63e2 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 11 Jul 2024 22:56:22 +0200 Subject: [PATCH] Fix handling of input toggle on cached form --- static/app.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/static/app.js b/static/app.js index 107a2a1..3b233c3 100644 --- a/static/app.js +++ b/static/app.js @@ -6,9 +6,11 @@ // Allows a form checkbox to toggle an input element. // This requires the form to have a structure like described in the bootstrap documentation: // https://getbootstrap.com/docs/5.3/forms/input-group/#checkboxes-and-radios + const inputToggle = target => { + target.parentElement.parentElement.querySelector("input:not(.input-toggle)").disabled = !target.checked + } Array.from(document.getElementsByClassName("input-toggle")).forEach(el => { - el.addEventListener("change", e => { - e.target.parentElement.parentElement.querySelector("input:not(.input-toggle)").disabled = !e.target.checked; - }) + inputToggle(el) + el.addEventListener("change", e => inputToggle(e.target)) }) })()