From b3702c00294a3624a88cf9db20c99cecb9ade3de Mon Sep 17 00:00:00 2001 From: Tim Aldinger Date: Tue, 29 Sep 2026 10:58:23 +0200 Subject: [PATCH] =?UTF-8?q?Klassennamen=20refactored,=20Eingabe=20f=C3=BCr?= =?UTF-8?q?=20Kategorie=20hinzugef=C3=BCgt,=20Umstrukturierung=20main.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit index.html: Klassennamen angepasst für bessere Übersichtlichkeit und neuen Form für Kategorie hinzugefügt main.js: Neue Klassennamen übernommen für query-selector und Methoden angepasst um Kategorie bei Items zu berücksichtigen --- index.html | 7 ++++++- src/main.js | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 09a4308..05f175b 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,12 @@
-
+ + Neue Kategorie hinzufügen: + +
+
+
Neuen Gegenstand hinzufügen: diff --git a/src/main.js b/src/main.js index ad08b6a..bdfb41f 100644 --- a/src/main.js +++ b/src/main.js @@ -1,13 +1,18 @@ import { ShoppingListItem } from "./ShoppingListItem"; -const form = document.querySelector(".list__inputForm"); +const addItemForm = document.querySelector(".list__form__addItem"); +const addCategoryForm = document.querySelector(".list__form__addCategory") const itemListElement = document.querySelector(".list__displayedList"); -let listItems = []; //list of items that the user has +let listElements = []; // Liste der erstellten Items und Kategorien +function addCategory() { + listCategories.push(new ShoppingCategory(categoryName)); + return 0; +} -function handleListElement(itemName, itemAmount,) { - listItems.push(new ShoppingListItem(itemName, itemAmount, renderList)); +function addNewItem(itemName, itemAmount, category) { + listElements.push(new ShoppingListItem(itemName, itemAmount, category, renderList)); renderList(); return 0; @@ -16,10 +21,10 @@ function handleListElement(itemName, itemAmount,) { function renderList() { - listItems = listItems.filter(item => !item.remove) + listElements = listElements.filter(item => !item.remove) itemListElement.innerHTML = ""; //reset innerItemList - listItems.forEach((element, index) => { + listElements.forEach((element, index) => { itemListElement.appendChild(element.render(index)); }); @@ -28,11 +33,11 @@ function renderList() { function init() { - document.querySelector(".list__inputForm").addEventListener("submit", (event) => { - if (!form.checkValidity()) return; + document.querySelector(".list__form__addItem").addEventListener("submit", (event) => { + if (!addItemForm.checkValidity()) return; event.preventDefault(); - const formData = Object.fromEntries(new FormData(form)); - handleListElement(formData.itemName, formData.itemAmount); + const addItemFormData = Object.fromEntries(new FormData(addItemForm)); + addNewItem(addItemFormData.itemName, addItemFormData.itemAmount); }); }