From a1bfe4f7c131061c17919e883ee3d36786a241e3 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 1 May 2026 11:58:12 +0300 Subject: [PATCH] close other add forms when opening a new one introduce closeAllAddForms which strips every add-child and bulk-add input/button from the tree, and call it at the start of toggleAddForm and toggleBulkAddForm (after the same-li toggle-off short-circuit, so clicking the same trigger still closes its own form). enforces a single open add form across the whole tree. --- public/js/text.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/public/js/text.js b/public/js/text.js index c15e711..90221d2 100644 --- a/public/js/text.js +++ b/public/js/text.js @@ -101,6 +101,21 @@ function renderTree(nodes, textId, depth = 0) { return ul; } +function closeAllAddForms() { + const selectors = [ + 'input.child-title', + 'button.save-child', + 'input.bulk-title', + 'input.bulk-count', + 'button.save-bulk', + ]; + selectors.forEach((selector) => { + document + .querySelectorAll('#text-detail ' + selector) + .forEach((element) => element.remove()); + }); +} + function toggleAddForm(li, parentNodeId, textId) { const existing = li.querySelector('input.child-title'); if (existing) { @@ -109,6 +124,8 @@ function toggleAddForm(li, parentNodeId, textId) { return; } + closeAllAddForms(); + const input = document.createElement('input'); input.type = 'text'; input.className = 'child-title'; @@ -158,6 +175,8 @@ function toggleBulkAddForm(li, parentNodeId, textId) { return; } + closeAllAddForms(); + const titleInput = document.createElement('input'); titleInput.type = 'text'; titleInput.className = 'bulk-title';