Fehler wird angezegit beim hinzufügen von Gegenstand und Kategorie
This commit is contained in:
1 parent
3962a58bc9
commit
719c63862e
1 file changed
+17
-4
@@ -15,15 +15,28 @@ const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButt
|
||||
async function addItem(itemName, itemAmount, categoryID) {
|
||||
console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
|
||||
const json = await handleResponse(api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID), `item couldnt be created!`);
|
||||
if (json.ok) ui.addItem(json.json);
|
||||
const response = await handleResponse(api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID), `item couldnt be created!`);
|
||||
if (response.ok) {
|
||||
ui.addItem(response.json);
|
||||
} else {
|
||||
const form = document.querySelector(".addItemForm");
|
||||
const name = document.querySelector(".addItemForm__nameInput");
|
||||
const amount = document.querySelector(".addItemForm__amountInput");
|
||||
showError({ highlightFields: [name, amount], elementForMessage: form, message: response.json.msg });
|
||||
}
|
||||
}
|
||||
|
||||
async function addCategory(categoryName) {
|
||||
console.log(`adding category ${categoryName}`)
|
||||
|
||||
const json = await handleResponse(api.addCategory(currentList.dataset.id, categoryName), `category couldnt be added!`);
|
||||
if (json.ok) ui.addCategory(json.json);
|
||||
const response = await handleResponse(api.addCategory(currentList.dataset.id, categoryName), `category couldnt be added!`);
|
||||
if (response.ok) {
|
||||
ui.addCategory(response.json);
|
||||
} else {
|
||||
const form = document.querySelector(".addCategoryForm");
|
||||
const name = document.querySelector(".addCategoryForm__nameInput");
|
||||
showError({ highlightFields: [name], elementForMessage: form, message: response.json.msg });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user