diff options
author | lucashemi <lucasxberger@gmail.com> | 2023-01-11 15:18:48 -0300 |
---|---|---|
committer | lucashemi <lucasxberger@gmail.com> | 2023-01-11 15:18:48 -0300 |
commit | 64e205aefba93f195c0498f41eda02513733a9c6 (patch) | |
tree | 5ff300dee22495a12fe93ad83e9f158fa66e370e /app/edit.js | |
parent | b1aee1997884e4bbd8d0667546ff96977550cb57 (diff) |
edit on focusout
Diffstat (limited to 'app/edit.js')
-rw-r--r-- | app/edit.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/app/edit.js b/app/edit.js index 9b2b732..1587882 100644 --- a/app/edit.js +++ b/app/edit.js @@ -18,7 +18,7 @@ function editElement(element, id) { const put = document.createElement('input'); put.style.fontSize = '0.9em'; - put.autofocus = true; + put.focus(); put.value = element.childNodes[0].textContent; forms.appendChild(put); @@ -27,12 +27,12 @@ function editElement(element, id) { forms.addEventListener('submit', (e) => { e.preventDefault(); + unhide(element, put, forms, id); + }, true); - id = jsList.findIndex(el => el.id == id) - jsList[id].name = put.value; - localStorage.setItem('jsList', JSON.stringify(jsList)); - - unhide(element, put, forms); + forms.addEventListener('focusout', (e) => { + e.preventDefault(); + unhide(element, put, forms, id); }, true); element.appendChild(forms); @@ -45,7 +45,7 @@ function hide(element) { element.childNodes[3].style.display = 'none'; } -function unhide(element, put, forms) { +function unhide(element, put, forms, id) { element.childNodes[0].textContent = put.value; element.childNodes[1].style.display = ''; element.childNodes[2].style.display = ''; @@ -53,4 +53,8 @@ function unhide(element, put, forms) { put.remove(); forms.remove(); + + id = jsList.findIndex(el => el.id == id); + jsList[id].name = put.value; + localStorage.setItem('jsList', JSON.stringify(jsList)); }
\ No newline at end of file |