From bd14bfd7a1a8f9da2df780fa7dd4822f82ae05ec Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 1 May 2026 11:55:43 +0300 Subject: [PATCH] submit bulk add form on enter key extract the save-bulk handler into a submit closure shared by the save button click and a keydown listener on both the title and count inputs. focus the title input as soon as the form opens. --- public/js/text.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/public/js/text.js b/public/js/text.js index 3b2b37e..c15e711 100644 --- a/public/js/text.js +++ b/public/js/text.js @@ -172,7 +172,8 @@ function toggleBulkAddForm(li, parentNodeId, textId) { const saveBtn = document.createElement('button'); saveBtn.textContent = 'Save'; saveBtn.className = 'save-bulk'; - saveBtn.addEventListener('click', () => { + + function submit() { const titlePrefix = titleInput.value.trim(); const count = parseInt(countInput.value); if (!titlePrefix || !count || count < 1) return; @@ -189,9 +190,21 @@ function toggleBulkAddForm(li, parentNodeId, textId) { return res.json(); }) .then(() => fetchAndRenderNodes(textId)); - }); + } + + function submitOnEnter(event) { + if (event.key === 'Enter') { + event.preventDefault(); + submit(); + } + } + + saveBtn.addEventListener('click', submit); + titleInput.addEventListener('keydown', submitOnEnter); + countInput.addEventListener('keydown', submitOnEnter); li.appendChild(titleInput); li.appendChild(countInput); li.appendChild(saveBtn); + titleInput.focus(); }