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.
This commit is contained in:
Yisroel Baum 2026-05-01 11:58:12 +03:00
parent d61d68571d
commit a1bfe4f7c1
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -101,6 +101,21 @@ function renderTree(nodes, textId, depth = 0) {
return ul; 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) { function toggleAddForm(li, parentNodeId, textId) {
const existing = li.querySelector('input.child-title'); const existing = li.querySelector('input.child-title');
if (existing) { if (existing) {
@ -109,6 +124,8 @@ function toggleAddForm(li, parentNodeId, textId) {
return; return;
} }
closeAllAddForms();
const input = document.createElement('input'); const input = document.createElement('input');
input.type = 'text'; input.type = 'text';
input.className = 'child-title'; input.className = 'child-title';
@ -158,6 +175,8 @@ function toggleBulkAddForm(li, parentNodeId, textId) {
return; return;
} }
closeAllAddForms();
const titleInput = document.createElement('input'); const titleInput = document.createElement('input');
titleInput.type = 'text'; titleInput.type = 'text';
titleInput.className = 'bulk-title'; titleInput.className = 'bulk-title';