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:
parent
ff8ec9a2ab
commit
bd14bfd7a1
1 changed files with 15 additions and 2 deletions
|
|
@ -172,7 +172,8 @@ function toggleBulkAddForm(li, parentNodeId, textId) {
|
||||||
const saveBtn = document.createElement('button');
|
const saveBtn = document.createElement('button');
|
||||||
saveBtn.textContent = 'Save';
|
saveBtn.textContent = 'Save';
|
||||||
saveBtn.className = 'save-bulk';
|
saveBtn.className = 'save-bulk';
|
||||||
saveBtn.addEventListener('click', () => {
|
|
||||||
|
function submit() {
|
||||||
const titlePrefix = titleInput.value.trim();
|
const titlePrefix = titleInput.value.trim();
|
||||||
const count = parseInt(countInput.value);
|
const count = parseInt(countInput.value);
|
||||||
if (!titlePrefix || !count || count < 1) return;
|
if (!titlePrefix || !count || count < 1) return;
|
||||||
|
|
@ -189,9 +190,21 @@ function toggleBulkAddForm(li, parentNodeId, textId) {
|
||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.then(() => fetchAndRenderNodes(textId));
|
.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(titleInput);
|
||||||
li.appendChild(countInput);
|
li.appendChild(countInput);
|
||||||
li.appendChild(saveBtn);
|
li.appendChild(saveBtn);
|
||||||
|
titleInput.focus();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue