by sam_goody · 3y ago · 0 comments
<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.
<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.