implementierung editItem Funktion
This commit is contained in:
1 parent
46024bd589
commit
2cb98af4f1
1 file changed
+37
@@ -22,6 +22,43 @@ async function addCategory(categoryName) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//textElement ist immer das li mit der id
|
||||
async function editItem(textElement) {
|
||||
|
||||
|
||||
//erstellen das Forms
|
||||
const formElement = ui.createEditItemForm(textElement)
|
||||
let id = textElement.id;
|
||||
|
||||
textElement.replaceWith(formElement);
|
||||
|
||||
formElement.querySelector(".editForm__name").focus();
|
||||
|
||||
function save() {
|
||||
let formData = Object.fromEntries(new FormData(formElement));
|
||||
|
||||
let newName = formData.newItemName;
|
||||
let newAmount = formData.newItemAmount;
|
||||
textElement.querySelector(".item__textName").textContent = newName;
|
||||
textElement.querySelector(".item__textAmount").textContent = newAmount;
|
||||
formElement.replaceWith(textElement);
|
||||
|
||||
console.log(`editing item ${id} with ${formData}`)
|
||||
api.editItem(id, { itemName: newName, itemAmount: newAmount });
|
||||
|
||||
}
|
||||
|
||||
formElement.addEventListener("submit", (event) => {
|
||||
save();
|
||||
});
|
||||
|
||||
formElement.addEventListener("keydown", (e) => {
|
||||
if (e.key == "Escape") formElement.replaceWith(textElement);
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
async function editCategory(categoryElement) {
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user