WIP on htmx 4; user messages now work (#60)

This commit is contained in:
2026-07-12 14:08:32 -04:00
parent d31b508359
commit 0fcb40fbdd
4 changed files with 26 additions and 33 deletions
+8 -9
View File
@@ -442,22 +442,21 @@ this.Admin = {
}
}
htmx.on("htmx:afterOnLoad", function (evt) {
const hdrs = evt.detail.xhr.getAllResponseHeaders()
htmx.on("htmx:after:swap", function (evt) {
// Initialize any toasts that were pre-rendered from the server
Admin.showPreRenderedMessages()
// Show messages if there were any in the response
if (hdrs.indexOf("x-message") >= 0) {
Admin.showMessage(evt.detail.xhr.getResponseHeader("x-message"))
const hdrs = evt.detail.ctx.response.headers
if (hdrs.has("x-message")) {
hdrs.get("x-message").split(", ").forEach(Admin.showMessage)
}
})
htmx.on("htmx:responseError", function (evt) {
const xhr = evt.detail.xhr
const hdrs = xhr.getAllResponseHeaders()
htmx.on("htmx:response:error", function (evt) {
const resp = evt.detail.ctx.response
// Show an error message if there were none in the response
if (hdrs.indexOf("x-message") < 0) {
Admin.showMessage(`danger|||${xhr.status}: ${xhr.statusText}`)
if (!resp.headers.has("x-message")) {
Admin.showMessage(`danger|||${resp.status}: ${resp.statusText}`)
}
})