renderEditing: Gegenstand kann bearbeitet werden

Die private renderEditing() Funktion erstellt ein <li> Element welches
Eingabefelder für Name und Menge, ein Speichern und Abbrechen Knopf
bereitstellt.
This commit is contained in:
Technoir committed 2026-09-29 09:53:59 +02:00
1 parent b92002f3cc
commit 567308acc4
1 file changed
+38
+38
View File
@@ -20,4 +20,42 @@ export class ShoppingListItem {
return li;
}
#renderEditing() {
const li = document.createElement("li");
const editForm = document.createElement("form");
const editNameField = document.createElement("input");
const editAmountField = document.createElement("input");
const saveButton = document.createElement("button");
const abortButton = document.createElement("button");
editNameField.setAttribute("name", "newItemName");
editAmountField.setAttribute("name", "newItemAmount");
abortButton.textContent = "Abbrechen";
abortButton.addEventListener("click", (event) => {
event.preventDefault();
this.isEditing = false;
this.onChange();
});
saveButton.textContent = "Speichern";
editForm.addEventListener("submit", (event) => {
event.preventDefault();
const editFormData = Object.fromEntries(new FormData(editForm));
this.name = editFormData.newItemName;
this.amount = editFormData.newItemAmount;
this.isEditing = false;
this.onChange();
});
editForm.appendChild(editNameField);
editForm.appendChild(editAmountField);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
li.appendChild(editForm);
return li;
}
}