From 3962a58bc9fd3bde63f15deddbf374bb118d3ab6 Mon Sep 17 00:00:00 2001 From: Tim Aldinger Date: Sat, 17 Oct 2026 15:34:54 +0200 Subject: [PATCH] edit Funktionen nutzen jtz showError --- .../resources/static/js/pages/list/list.js | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/main/resources/static/js/pages/list/list.js b/src/main/resources/static/js/pages/list/list.js index dbc6a7a..28fc0f6 100644 --- a/src/main/resources/static/js/pages/list/list.js +++ b/src/main/resources/static/js/pages/list/list.js @@ -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` });