From e76bc9c0b2355985d6d1ade7e3aed03477e84035 Mon Sep 17 00:00:00 2001 From: Jim Brandt Date: Tue, 10 Dec 2024 14:36:23 -0500 Subject: [PATCH] Use growl messages for non-GET htmx request errors --- .../response-targets-rt.js | 16 ++++++++++++---- share/static/js/response-targets-rt.min.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/devel/third-party/htmx-ext-response-targets-2.0.1/response-targets-rt.js b/devel/third-party/htmx-ext-response-targets-2.0.1/response-targets-rt.js index 95cc3185a2..e119e9e75a 100644 --- a/devel/third-party/htmx-ext-response-targets-2.0.1/response-targets-rt.js +++ b/devel/third-party/htmx-ext-response-targets-2.0.1/response-targets-rt.js @@ -117,7 +117,8 @@ return true } var target = getRespCodeTarget(evt.detail.requestConfig.elt, evt.detail.xhr.status) - if (target) { + + if (target && evt.detail.requestConfig.verb === "get") { handleErrorFlag(evt) evt.detail.shouldSwap = true /* The extension re-targets the response, which is an error message, @@ -128,9 +129,12 @@ We mostly do GETs to load content from the server, so we want something slightly different. We want to replace the server error - with a formatted custom error message. To do so, leave the target - as the original calling component, but replace the serverResponse - with our custom message, pulled from hidden content on the page. */ + with a formatted custom error message, and display it inside the + component that failed so it's clear which component had an issue. + + To do so, leave the target as the original calling component, but + replace the serverResponse with our custom message, pulled from + hidden content on the page. */ // Remove extension default behavior // evt.detail.target = target @@ -138,6 +142,10 @@ // Replace with our own version evt.detail.serverResponse = target.outerHTML; } + else if (target) { + // For POSTs, use growl messages since there may not be an obvious container to replace + jQuery.jGrowl(target.outerHTML, { sticky: true, themeState: 'none' }); + } return true } diff --git a/share/static/js/response-targets-rt.min.js b/share/static/js/response-targets-rt.min.js index 29defd88dd..5fa0daa17e 100644 --- a/share/static/js/response-targets-rt.min.js +++ b/share/static/js/response-targets-rt.min.js @@ -1 +1 @@ -(function(){var api;var attrPrefix="hx-target-";function startsWith(str,prefix){return str.substring(0,prefix.length)===prefix}function getRespCodeTarget(elt,respCodeNumber){if(!elt||!respCodeNumber)return null;var respCode=respCodeNumber.toString();var attrPossibilities=[respCode,respCode.substring(0,2)+"*",respCode.substring(0,2)+"x",respCode.substring(0,1)+"*",respCode.substring(0,1)+"x",respCode.substring(0,1)+"**",respCode.substring(0,1)+"xx","*","x","***","xxx"];if(startsWith(respCode,"4")||startsWith(respCode,"5")){attrPossibilities.push("error")}for(var i=0;i