adventurous-ocean-93733
05/05/2023, 4:07 PMmysterious-toddler-20573
05/05/2023, 4:10 PMwitty-account-33479
05/05/2023, 4:17 PM#topics
. In this span's onchange
attribute I call a js validation function. I also need to call the function once when the elements arrive. I don't think it matters much if it's on "load" or "afterSettle" or some other point.
The easiest way I could see to do this was to handle this was with a global htmx.onLoad listener:
addEventListener('DOMContentLoaded', ()=> {
htmx.onLoad((el)=> {
if ((topics = el.querySelector('#topics'))) {
validate_topics_checkboxes(el)
}
});
});
Another thing I tried was to add an inline script element alongside the span in the htmx response. Surprisingly this caused the function to be called twice. In my case it's not terrible to call validation twice, but in general this seems like a bug or at least undesirable/unsupported behavior. Should I file an issue for this?
Ultimately, my question is whether there is a way to do this with better locality to the DOM element. In my ideal world onload would work on all elements and I could just write <span id="topics" onload="validate_topics_checkboxes()" onchange="validate_topics_checkboxes()">
. Sadly that's not how onload works.
From the docs I see that LoB is valued by the authors, so I wonder if this is something that has been hashed out before. Thanks in advance!mysterious-toddler-20573
05/05/2023, 4:30 PMhttps://cdn.discordapp.com/attachments/725789747212976259/1104082772760465408/image.png▾
mysterious-toddler-20573
05/05/2023, 4:31 PMhttps://cdn.discordapp.com/attachments/725789747212976259/1104082866838708354/iu.png▾
ripe-action-67367
05/05/2023, 4:37 PMhttps://cdn.discordapp.com/attachments/725789747212976259/1104084380449783920/image.png▾
ripe-action-67367
05/05/2023, 4:37 PMhttps://cdn.discordapp.com/attachments/725789747212976259/1104084424817115246/image.png▾
ripe-action-67367
05/05/2023, 4:38 PMmysterious-toddler-20573
05/05/2023, 4:44 PMmysterious-toddler-20573
05/05/2023, 4:44 PMgreat-article-50141
05/05/2023, 4:45 PMmysterious-toddler-20573
05/05/2023, 4:45 PMhttps://cdn.discordapp.com/attachments/725789747212976259/1104086602235523099/image.png▾
mysterious-toddler-20573
05/05/2023, 4:46 PMgreat-article-50141
05/05/2023, 4:46 PMgreat-article-50141
05/05/2023, 4:46 PMbitter-monkey-50309
05/05/2023, 5:47 PMdazzling-shoe-67340
05/05/2023, 5:48 PMgorgeous-ghost-95789
05/05/2023, 5:53 PMload
. You may want to check out [hx-on
](https://htmx.org/attributes/hx-on/) which helps you to capture htmx events like htmx:load
, etc.bitter-machine-55943
05/05/2023, 6:16 PMadamant-state-54102
05/05/2023, 7:42 PMvictorious-artist-2344
05/05/2023, 7:44 PMgorgeous-airport-54386
05/05/2023, 7:45 PMadamant-state-54102
05/05/2023, 7:45 PMvictorious-artist-2344
05/05/2023, 7:46 PMvictorious-artist-2344
05/05/2023, 7:47 PMadamant-state-54102
05/05/2023, 7:48 PMvictorious-artist-2344
05/05/2023, 7:49 PMvictorious-artist-2344
05/05/2023, 7:49 PMvictorious-artist-2344
05/05/2023, 7:53 PMadamant-state-54102
05/05/2023, 7:53 PM