mysterious-toddler-20573
01/23/2023, 3:44 PMgray-morning-3453
01/23/2023, 5:27 PMhtmx:beforeSend
and htmx:afterRequest
like this, so that it closes when htmx tells it that request has completed:
form.addEventListener('htmx:beforeSend', function() {
// Show the loading spinner
spinner_container.classList.remove("hidden");
spinner_container.classList.add("block");
});
form.addEventListener('htmx:afterRequest', function(){
mainModalClose();
});
3. And now it works. The server is sending a message back to the client via the hx-trigger and it is handled not by the form but by the body's event listener and shown in a toast. I intend to use the same mechanism for other parts of the app as well, so that is why the handler is with the body.
My question is, is this okay? Is using htmx:afterRequest
okay? Or should I send another event from server, explicitly to tell the form to close itself?late-king-98305
01/23/2023, 5:52 PMDOMContentLoaded
, but htmx-swapped content doesn't do that. The solution ended up being 5 lines in F#, but I thought I'd share it here for non-F# folks, as the algorithm is the same.
For context - the jsOnLoad
function writes a script
tag that will fire once the content is loaded. For my case, I have a textarea
where Markdown can be written, and a "Preview" button that will replace that with a preview. It's handy for attaching event listeners, etc.late-king-98305
01/23/2023, 5:52 PMfsharp
let jsOnLoad js isHtmx =
script [] [
let (target, event) = if isHtmx then "document.body", "htmx:afterSettle" else "document", "DOMContentLoaded"
txt (sprintf """%s.addEventListener("%s", () => { %s }, { once: true })""" target event js)
]
mysterious-toddler-20573
01/23/2023, 5:54 PMbillions-easter-81130
01/23/2023, 8:20 PM<head>
of every page? Something like hacking preload to preload external scripts instead of images, for example?billions-easter-81130
01/23/2023, 8:53 PMhx-boost="false"
on any <a href="">
tag that links to a page which will request additional JS resources, but it would be feasible to put some sort of "if you came here from a boosted page, please load me the traditional way instead"-tag on those pages.bumpy-kangaroo-60192
01/23/2023, 10:58 PMbumpy-kangaroo-60192
01/23/2023, 10:58 PMmysterious-toddler-20573
01/23/2023, 11:20 PMlimited-potato-46306
01/24/2023, 3:07 AMlimited-potato-46306
01/24/2023, 3:39 AMhundreds-camera-24900
01/24/2023, 3:56 AMsalmon-church-58191
01/24/2023, 9:57 AMgentle-tomato-75013
01/24/2023, 11:10 AMbland-coat-6833
01/24/2023, 11:16 AMhx-post
on the <td>
but it looks like the hyperscript is triggering first. Is there any easy way to achieve what I want?gentle-tomato-75013
01/24/2023, 12:48 PMbland-coat-6833
01/24/2023, 12:57 PMmysterious-toddler-20573
01/24/2023, 2:34 PMorange-nail-40296
01/24/2023, 3:27 PMhundreds-camera-24900
01/24/2023, 4:34 PMmammoth-family-48524
01/24/2023, 8:15 PMadventurous-ocean-93733
01/24/2023, 8:19 PMGET
sleep when you can
POST
online to friends if you need support
PUT
some time aside for you and your wife to dedicate to each other
DELETE
everything in your calendar for next 2 months!billions-easter-81130
01/24/2023, 8:30 PMdjango-select2
and django-tinymce
) will add their own, custom .js
files, which are by default only loaded when required by a rendered form, so I might have to go in and do quite some manual work. To be honest, I might be better off using hx-boost="false"
for the time being. ๐ญbillions-easter-81130
01/24/2023, 8:37 PMhx-boost="false"
to those, I would instead just add a little <meta htmx-unboost="true">
on my form template's <head>
. Then I'd have boosting where it's not problematic / easily handled by including some additional .js
files in my default <head>
, but all my pages containing certain form elements should still work because they will only be loaded like it's 1999.mysterious-toddler-20573
01/24/2023, 8:50 PMbillions-easter-81130
01/24/2023, 8:58 PM<a href="/maintenance/task/add/">Add new task</a>
and even though this link has inherited hx-boost="true"
, because there's some special marker/tag included in the response, htmx let's the browser render the entire response as a whole instead of merging it into the DOMmysterious-toddler-20573
01/24/2023, 10:13 PMagreeable-apartment-19546
01/25/2023, 12:00 AMmysterious-toddler-20573
01/25/2023, 12:04 AM