addList() implementiert und eventHandler für das hinzufügen von Listen am Form hinzugefügt
This commit is contained in:
1 parent
66e8ac13ea
commit
b5d61ff772
1 file changed
+14
-10
@@ -1,9 +1,14 @@
|
||||
import { ShoppingList } from "./ShoppingList.js";
|
||||
import { ShoppingList } from "../../models/ShoppingList.js";
|
||||
import * as api from "./api/indexAPI.js";
|
||||
import * as ui from "./frontend/indexUI.js"
|
||||
|
||||
const addListForm = document.querySelector(".addListForm");
|
||||
|
||||
const deleteListButtons = document.querySelectorAll('.shoppingListOverview__deleteListButton');
|
||||
const shoppingLists = [];
|
||||
|
||||
async function addList(listName) {
|
||||
const listAsJson = await api.addList(listName);
|
||||
console.log(`${listAsJson}`);
|
||||
if (listAsJson) ui.addList(listAsJson);
|
||||
}
|
||||
|
||||
function fillList() {
|
||||
document.querySelectorAll('.shoppingListOverview__shoppingList')
|
||||
@@ -20,13 +25,12 @@ function deleteList(id) {
|
||||
|
||||
|
||||
function init() {
|
||||
deleteListButtons.forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const id = button.dataset.id; // liest data-id
|
||||
deleteList(id);
|
||||
});
|
||||
addListForm.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
const formData = Object.fromEntries(new FormData(addListForm));
|
||||
addList(formData.listName);
|
||||
});
|
||||
fillList();
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
Reference in new issue
Block a user