indexseite zeigt fehlermeldungen an
This commit is contained in:
1 parent
a5f0fa9ba3
commit
433445290c
1 file changed
+19
-6
@@ -1,6 +1,6 @@
|
||||
import { ShoppingList } from "../../models/ShoppingList.js";
|
||||
import { editElement } from "../../shared/editing.js";
|
||||
import { initErrors } from "../../shared/error.js";
|
||||
import { showError } from "../../shared/error.js";
|
||||
import { handleResponse } from "../../shared/helper.js";
|
||||
import { setElementAttributes } from "../../shared/sharedUI.js";
|
||||
import * as api from "./api/indexAPI.js";
|
||||
@@ -9,18 +9,23 @@ import * as ui from "./frontend/indexUI.js"
|
||||
const addListForm = document.querySelector(".addListForm");
|
||||
|
||||
async function addList(listName) {
|
||||
const json = await handleResponse(api.addList(listName), `error creating list`);
|
||||
if (json) ui.addList(json);
|
||||
const response = await handleResponse(api.addList(listName), `error creating list`);
|
||||
if (response.ok) {
|
||||
ui.addList(response.json);
|
||||
} else {
|
||||
const name = document.querySelector(".addListForm__inputName");
|
||||
showError({ highlightFields: [name], elementForMessage: addListForm, message: response.msg });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function deleteList(listElement) {
|
||||
const json = await handleResponse(api.deleteList(listElement.dataset.id), `error deleting list`);
|
||||
if (json) ui.deleteList(listElement);
|
||||
const response = await handleResponse(api.deleteList(listElement.dataset.id), `error deleting list`);
|
||||
if (response.ok) ui.deleteList(listElement);
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
initErrors(document.querySelector(".nav"));
|
||||
customElements.define("shopping-list", ShoppingList);
|
||||
|
||||
addListForm.addEventListener("submit", (e) => {
|
||||
@@ -44,6 +49,14 @@ function init() {
|
||||
setElementAttributes(shoppingListElement, { "list-name": f.listName });
|
||||
//nav wird hier ^ aktualisiert
|
||||
}
|
||||
, onFailure: (response) => {
|
||||
|
||||
const editForm = document.querySelector(".editForm");
|
||||
const name = document.querySelector("input.editForm__name");
|
||||
|
||||
showError({ highlightFields: [name], elementForMessage: editForm, message: response.json.msg });
|
||||
}
|
||||
|
||||
, errmsg: `liste konnte nicht aktualsiiert werden`
|
||||
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user