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:
1 parent
b92002f3cc
commit
567308acc4
1 file changed
+38
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user