From: Christian Heller Date: Tue, 28 Jan 2025 13:05:38 +0000 (+0100) Subject: Replace Booking edit taint handlers from .onchange to .oninput, but remove once used. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/new_day?a=commitdiff_plain;h=f6cecc4267d62a514208af83432f6b9efd881c5f;p=plomledger Replace Booking edit taint handlers from .onchange to .oninput, but remove once used. --- diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index bf9bff5..5afc960 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -54,20 +54,26 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; } {% macro taint_js() %} function taint() { - let els = document.getElementsByClassName("enable_on_change"); - for (let i = 0; i < els.length; i++) { - els[i].disabled = false; - } - let links_text = ''; - els = document.getElementsByClassName("disable_on_change"); - for (let i = 0; i < els.length; i++) { - links_text += els[i].textContent + ' '; - } + // activate buttons "apply", "revert" + Array.from(document.getElementsByClassName("enable_on_change")).forEach((el) => { + el.disabled = false; + }); + // deactivate Booking links + Array.from(document.getElementsByClassName("disable_on_change")).forEach((el) => { + links_text += el.textContent + ' '; + }); const span = document.getElementById('booking_links'); + let links_text = ''; span.innerHTML = ''; const del = document.createElement("del"); span.appendChild(del); del.textContent = links_text; + // remove oninput handlers no longer needed (since we only ever go one way) + ['input', 'textarea'].forEach((tag_name) => { + Array.from(document.getElementsByTagName(tag_name)).forEach((el) => { + el.oninput = null; + }); + }); } {% endmacro %} diff --git a/templates/edit_raw.tmpl b/templates/edit_raw.tmpl index 6e3702d..b58e7b3 100644 --- a/templates/edit_raw.tmpl +++ b/templates/edit_raw.tmpl @@ -15,7 +15,7 @@ {% block content %}
{{ macros.edit_bar("structured", id) }} -
diff --git a/templates/edit_structured.tmpl b/templates/edit_structured.tmpl index 6e31d91..0e510ae 100644 --- a/templates/edit_structured.tmpl +++ b/templates/edit_structured.tmpl @@ -40,7 +40,7 @@ function update_form() { input.name = `line_${i}_${name}` input.value = value.trim(); input.placeholder = placeholder; - input.onchange = taint; + input.oninput = taint; if (dat_line.error) { td.classList.add("invalid"); }