Kategorie kann nun bearbeitet werden
This commit is contained in:
1 parent
371a8a508e
commit
80d981be74
1 file changed
+40
@@ -23,6 +23,46 @@ export class ShoppingCategory {
|
||||
}
|
||||
|
||||
#renderEditing() {
|
||||
//const li = document.createElement("li");
|
||||
const editForm = document.createElement("form");
|
||||
const editCategoryNameField = document.createElement("input");
|
||||
const saveButton = document.createElement("button");
|
||||
const abortButton = document.createElement("button");
|
||||
|
||||
|
||||
editCategoryNameField.setAttribute("name", "newCategoryName");
|
||||
editCategoryNameField.setAttribute("value", this.categoryName);
|
||||
|
||||
|
||||
abortButton.textContent = "Abbrechen";
|
||||
abortButton.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
this.isEditing = false;
|
||||
this.onUpdate();
|
||||
});
|
||||
|
||||
saveButton.textContent = "Speichern";
|
||||
editForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const editFormData = Object.fromEntries(new FormData(editForm));
|
||||
|
||||
if (!editFormData.newCategoryName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.categoryName = editFormData.newCategoryName;
|
||||
this.isEditing = false;
|
||||
this.onUpdate();
|
||||
this.onDelete();
|
||||
});
|
||||
|
||||
editForm.appendChild(editCategoryNameField);
|
||||
editForm.appendChild(saveButton);
|
||||
editForm.appendChild(abortButton);
|
||||
//li.appendChild(editForm);
|
||||
|
||||
return editForm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user