3 ms·
I know I will get downvoted for this and people will just say "you're doing it wrong" or "the library wasn't designed for that" but I still think it would be re
by ranger_danger 9mo ago
I know I will get downvoted for this and people will just say "you're doing it wrong" or "the library wasn't designed for that" but I still think it would be really helpful for some people if the source of the data to swap out could be retrieved from parsing the response data as JSON and grabbing a certain named key.
Yes one can add a callback function to parse the data as JSON, do error handling etc. and then swap the text/HTML, but having that built in to a hx-foo attribute would be a lot easier.
- test1072 9mo agoNo idea much about htmx but can we write custom extension something to add to htmx ?
- wild_egg 9mo agoI'm really struggling to think of a scenario where I would want to do something like that. What use case do you have in mind?
- ranger_danger 9mo agoRe-using existing API calls that I can't change, where I want to replace the text of an html element with the text from a specific key in a json response.
- evolve-maz 9mo agoHtmx has events you can listen to like htmx after response. You can think of it almost like a middleware. After the response comes in, your callback is triggered and you can make the callback look up some attribute given the calling parents attribute that you might call hx-json-key. Yes you have to add this yourself, but you only need to add one js function once and be done with it. I've used the callback pattern for custom error handling for all hx responses.