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:
1 parent
3be624df0d
commit
b3702c0029
2 files changed
+21
-11
No files matched your search
+6
-1
@@ -13,7 +13,12 @@
|
||||
</div>
|
||||
|
||||
<div class="list">
|
||||
<form class="list__inputForm">
|
||||
<form class="list__form__addCategory">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="list__inputForm__categoryName">
|
||||
</form>
|
||||
<br>
|
||||
<form class="list__form__addItem">
|
||||
<span>Neuen Gegenstand hinzufügen:</span>
|
||||
<input type="text" class="list__inputForm__itemName" name="itemName" placeholder="Gegenstand eingeben...">
|
||||
<input type="text" class="list__inputForm__itemAmount" name="itemAmount" placeholder="Menge eingeben...">
|
||||
|
||||
+15
-10
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user