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

View file

@ -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();
}