editList implementiert

funktionert wie die anderen zwei kack dinger
This commit is contained in:
Technoir committed 2026-10-09 23:07:52 +02:00
1 parent f83f3bf4b1
commit ddec4d8335
1 file changed
+29 -1
@@ -10,7 +10,34 @@ async function addList(listName) {
if (listAsJson) ui.addList(listAsJson);
}
function editList() {
function editList(listLi) {
//erstellen das Forms
//wir nutzen für das Element nur das div, weil sonst alle items mitgelöscht werden würden
const formElement = ui.createEditListForm(listLi);
let id = listLi.id;
listLi.replaceWith(formElement);
formElement.querySelector(".editForm__name").focus();
function save() {
let formData = Object.fromEntries(new FormData(formElement));
ui.editList(id, formElement, formData, listLi);
console.log(`editing catogory ${id} with ${formData}`)
api.editList(id, { newListName: formData.newListName });
}
formElement.addEventListener("submit", (event) => {
event.preventDefault();
save();
});
formElement.addEventListener("keydown", (e) => {
if (e.key == "Escape") formElement.replaceWith(listLi);
})
}
@@ -31,6 +58,7 @@ function init() {
document.querySelector(".index").addEventListener("click", (event) => {
if (event.target.matches(".list__editButton")) {
editList(event.target.closest("li"));
} else if (event.target.matches(".list__deleteButton")) {
deleteList(event.target.closest("li"));