From 33b0d4b3c628bc8fa0ff35f7f88af9aa2224cf5c Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sat, 6 Jun 2026 16:53:56 +0200 Subject: [PATCH] feat: add htmx error toast on error class swap --- static/htmx.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/htmx.ts b/static/htmx.ts index 9a2aeb9..9214a30 100644 --- a/static/htmx.ts +++ b/static/htmx.ts @@ -54,6 +54,14 @@ onReady(() => { toast("Something went wrong"); }); + document.addEventListener("htmx:afterSwap", (event) => { + const detail = event as CustomEvent<{ target?: EventTarget | null }>; + const target = detail.detail?.target; + if (!(target instanceof HTMLElement)) return; + if (!target.classList.contains("error")) return; + toast("Failed to load content"); + }); + document.addEventListener("htmx:sendError", () => { toast("Network error"); });