Klassennamen refactored, Eingabe für Kategorie hinzugefügt, Umstrukturierung main.js

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
This commit is contained in:
Technoir committed 2026-09-29 10:58:23 +02:00
1 parent 3be624df0d
commit b3702c0029
2 files changed
+21 -11

No files matched your search

+15 -10
View File
@@ -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);
});
}