diff --git a/assets/admin.js b/assets/admin.js index 31522a7..27c16bd 100644 --- a/assets/admin.js +++ b/assets/admin.js @@ -81,4 +81,20 @@ window.addEventListener("load", () => { } } }); + + // Open accordions with errors on submit. + document.addEventListener("ea.form.error", (event) => { + const { page, form } = event.detail; + // alert(`The ${page} form contains errors. Please resolve these before submitting again.`) + const elements = form.querySelectorAll(".accordion-item .has-error"); + for (const el of elements) { + const item = el.closest(".accordion-item"); + const button = item?.querySelector(".accordion-header button"); + const contents = item?.querySelector(".accordion-collapse"); + if (button && contents) { + button.classList.remove("collapsed"); + contents.classList.add("show"); + } + } + }); });