home · contact · privacy
In /edit_structured disable replace button if un-applied changes.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 16:25:58 +0000 (17:25 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 16:25:58 +0000 (17:25 +0100)
src/templates/_macros.tmpl
src/templates/edit_structured.tmpl

index a3187c9b62709c41f62320c7c244e6c0ac9aed9d..35a4173058d0e96c88a6ebc7ba12a0d6b56ed10e 100644 (file)
@@ -101,23 +101,27 @@ table.ledger tr > td:first-child { background-color: white; }
 function taint() {
   // activate buttons "apply", "revert"
   Array.from(document.getElementsByClassName("enable_on_change")).forEach((el) => {
-    el.disabled = false;
+      el.disabled = false;
   });
   // deactivate Booking links
-  Array.from(document.getElementsByClassName("disable_on_change")).forEach((span) => {
-    let links_text = '';
-    Array.from(span.childNodes).forEach((node) => {
-      links_text += node.textContent + ' ';
-    });
-    span.innerHTML = '';
-    const del = document.createElement("del");
-    span.appendChild(del);
-    del.textContent = links_text;
+  Array.from(document.getElementsByClassName("disable_on_change")).forEach((el) => {
+      if (el.tagName == 'span') {
+          let links_text = '';
+          Array.from(el.childNodes).forEach((node) => {
+            links_text += node.textContent + ' ';
+          });
+          el.innerHTML = '';
+          const del = document.createElement("del");
+          el.appendChild(del);
+          del.textContent = links_text;
+      } else if (el.type == "button") {
+          el.disabled = true;
+      }
   });
   // 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;
+          el.oninput = null;
       });
   });
 }
index 298510c663d3a1273dc963d263f8dbd2feb56d41..de2a2264e91829508c572487fb7dd4b9d40bd1e2 100644 (file)
@@ -147,8 +147,8 @@ function update_form() {
   table.appendChild(tr);
   const td = add_td(tr, 5);
   add_button(td, 'add line', false, function() {
-   new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}};
-   dat_lines.push(new_line);
+    new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}};
+    dat_lines.push(new_line);
   });
 
   // make all rows alternate background color for better readability
@@ -182,7 +182,7 @@ window.onload = update_form;
 {% block content %}
 <form action="/edit_structured/{{id}}" method="POST">
 {{ macros.edit_bar("raw", id) }}
-<input type="button" onclick="replace()" value="replace string">
+<input type="button" onclick="replace()" value="replace string" class="disable_on_change">
 from
 <input id="replace_from" />
 to