diff --git a/web/static/mcias.js b/web/static/mcias.js index 7a6492f..4dcc454 100644 --- a/web/static/mcias.js +++ b/web/static/mcias.js @@ -1,4 +1,8 @@ -// mcias.js — HTMX event wiring for the MCIAS web UI. +// mcias.js — HTMX event wiring and CSP-safe UI helpers for the MCIAS web UI. +// +// All interactive behavior that would otherwise require inline onclick/onchange +// handlers is wired here via data-* attributes so that script-src 'self' +// (without 'unsafe-inline') is sufficient. // Show server error responses in the global #htmx-error-banner. // @@ -15,9 +19,17 @@ document.body.addEventListener('htmx:responseError', function (evt) { banner.scrollIntoView({ behavior: 'instant', block: 'nearest' }); }); -// Toggle visibility of a create-form panel. The button text alternates -// between the given labels. Used by admin pages (accounts, policies, -// pgcreds, SSO clients) to show/hide the inline create form. +// Clear the error banner whenever a successful HTMX swap completes so +// stale errors do not persist after the user corrects their input. +document.body.addEventListener('htmx:afterSwap', function () { + var banner = document.getElementById('htmx-error-banner'); + if (banner) { + banner.style.display = 'none'; + banner.innerHTML = ''; + } +}); + +// --- Toggle-form buttons --- // // Usage: -