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';