3 ms·
HTMX should have a way to have JS modify the response before it is inserted/handled. <div hx-preinsert="myfunc">Old Content</div> <script> function myf
by sam_goody 4y ago
HTMX should have a way to have JS modify the response before it is inserted/handled.
<div hx-preinsert="myfunc">Old Content</div>
<script> function myfunc(callingElement, serverResponse){
return modified-Server-Response
}
IMO, aside from the fact that such a feature really is needed, the lack thereof pushes people to Marko, Livewire, etc, simply because they need to do add some tiny detail which is available in the JS. Besides that it makes HTMX look like a toy that values purity (no frontend JS) over practicality.
I know there are ways to build a plugin, but do not have the time or headspace to figure it out.
- kaeshiwaza 4y agoMaybe the new feature 'hx-on' can help with that ?
- recursivedoubts 4y agoYou can use the `htmx:beforeSwap` event to transform responses if you'd like: <button hx-get="/example" hx-on="htmx:beforeSwap: event.detail.serverResponse = transformResponse(event.detail.serverResponse)"> Example </button> In general, htmx is going to lean on events for integrating scripting into the hypermedia flow.