vite hinzugefügt und Dateien verschoben
This commit is contained in:
1 parent
ed6104cdba
commit
1591f6e3b2
6 files changed
+867
-25
No files matched your search
+60
@@ -0,0 +1,60 @@
|
||||
|
||||
const form = document.querySelector(".list__inputForm");
|
||||
const itemList = document.querySelector(".list__displayedList");
|
||||
|
||||
let listItems = []; //list of items that the user has
|
||||
|
||||
|
||||
function handleListElement(itemName, itemAmount,) {
|
||||
listItems.push({ name: itemName, amount: itemAmount });
|
||||
renderList();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function renderList() {
|
||||
itemList.innerHTML = ""; //reset innerItemList
|
||||
|
||||
listItems.forEach((element, index) => {
|
||||
const li = document.createElement("li");
|
||||
const removeButton = document.createElement("button");
|
||||
const editButton = document.createElement("button");
|
||||
const doneButton = document.createElement("input");
|
||||
|
||||
doneButton.setAttribute("type", "checkbox");
|
||||
doneButton.addEventListener("change", () => {
|
||||
listItems[index].done = doneButton.checked;
|
||||
});
|
||||
|
||||
editButton.textContent = "Bearbeiten"
|
||||
removeButton.textContent = "Löschen";
|
||||
removeButton.addEventListener("click", () => {
|
||||
listItems.splice(index, 1);
|
||||
renderList();
|
||||
});
|
||||
|
||||
li.textContent = element.name + " " + element.amount;
|
||||
li.appendChild(removeButton);
|
||||
li.appendChild(doneButton);
|
||||
li.appendChild(editButton);
|
||||
|
||||
|
||||
itemList.appendChild(li);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
|
||||
document.querySelector(".list__inputForm").addEventListener("submit", (event) => {
|
||||
if (!form.checkValidity()) return;
|
||||
event.preventDefault();
|
||||
const formData = Object.fromEntries(new FormData(form));
|
||||
handleListElement(formData.itemName, formData.itemAmount);
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
li:has(input:checked){
|
||||
text-decoration: line-through;
|
||||
}
|
||||
Reference in new issue
Block a user