submit add child form on enter key
extract the save-child handler into a submit closure shared by the save button click and a keydown listener on the input. also focus the input as soon as the form opens so the user can type and hit enter without touching the mouse.
This commit is contained in:
parent
74705379cb
commit
3928fef213
1 changed files with 11 additions and 1 deletions
|
|
@ -117,7 +117,8 @@ function toggleAddForm(li, parentNodeId, textId) {
|
|||
const saveBtn = document.createElement('button');
|
||||
saveBtn.textContent = 'Save';
|
||||
saveBtn.className = 'save-child';
|
||||
saveBtn.addEventListener('click', () => {
|
||||
|
||||
function submit() {
|
||||
const title = input.value.trim();
|
||||
if (!title) return;
|
||||
|
||||
|
|
@ -133,10 +134,19 @@ function toggleAddForm(li, parentNodeId, textId) {
|
|||
return res.json();
|
||||
})
|
||||
.then(() => fetchAndRenderNodes(textId));
|
||||
}
|
||||
|
||||
saveBtn.addEventListener('click', submit);
|
||||
input.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
submit();
|
||||
}
|
||||
});
|
||||
|
||||
li.appendChild(input);
|
||||
li.appendChild(saveBtn);
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function toggleBulkAddForm(li, parentNodeId, textId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue