edit Funktionen nutzen jtz showError

This commit is contained in:
Technoir committed 2026-10-17 15:34:54 +02:00
1 parent 921d7aef72
commit 3962a58bc9
1 file changed
+5 -27
@@ -5,7 +5,7 @@ import * as ui from "./frontend/listUI.js"
import { handleResponse } from "../../shared/helper.js";
import { editElement } from "../../shared/editing.js";
import * as sharedUI from "../../shared/sharedUI.js";
import { createErrorSpan } from "../../shared/error.js";
import { createErrorSpan, showError } from "../../shared/error.js";
const addCategoryForm = document.querySelector(".addCategoryForm");
const addItemForm = document.querySelector(".addItemForm");
@@ -99,26 +99,12 @@ function init() {
]
, onSuccess: (f) => { sharedUI.setElementAttributes(shoppingItemElement, { "item-name": f.itemName, "item-amount": f.itemAmount }) }
, onFailure: (response) => {
let errorTimer;
const editForm = document.querySelector(".editForm");
const name = document.querySelector("input.editForm__name");
const amount = document.querySelector("input.editForm__amount")
const err = createErrorSpan(response.json.msg);
name.classList.add("is-invalid");
amount.classList.add("is-invalid");
editForm.append(err);
clearTimeout(errorTimer);
errorTimer = (setTimeout(() => {
name.classList.remove("is-invalid");
amount.classList.remove("is-invalid")
editForm.removeChild(err);
}, 5000));
showError({ highlightFields: [name, amount], elementForMessage: editForm, message: response.json.msg });
}
, errmsg: `konnte Item nicht bearbeiten`
});
@@ -141,20 +127,12 @@ function init() {
document.querySelector(`option[value='${id}']`).textContent = f.categoryName;
}
, onFailure: (response) => {
let errorTimer;
const editForm = document.querySelector(".editForm");
const editName = document.querySelector(".editForm__name");
const err = createErrorSpan(response.json.msg);
const name = document.querySelector(".editForm__name");
editName.classList.add("is-invalid");
editForm.append(err);
showError({ highlightFields: [name], elementForMessage: editForm, message: response.json.msg });
clearTimeout(errorTimer);
errorTimer = (setTimeout(() => {
editName.classList.remove("is-invalid");
editForm.removeChild(err);
}, 5000));
}
, errmsg: `konnte Kategorie nicht bearbeiten`
});