great-cartoon-12331
04/29/2023, 10:02 PMgreat-cartoon-12331
04/29/2023, 10:03 PMrefined-waiter-90422
04/29/2023, 10:39 PMrefined-waiter-90422
04/29/2023, 10:40 PMrefined-waiter-90422
04/29/2023, 10:41 PMrefined-waiter-90422
04/29/2023, 10:41 PMbitter-machine-55943
04/29/2023, 10:51 PMrefined-waiter-90422
04/29/2023, 10:52 PMrefined-waiter-90422
04/29/2023, 10:54 PMmysterious-toddler-20573
04/30/2023, 1:46 AMHX-Redirect
response header? And then show an error message w/ HX-Trigger
response header?great-cartoon-12331
04/30/2023, 1:47 AMproud-librarian-99598
04/30/2023, 8:44 AMhx-trigger="sl-selection-change[detail.selection.includes(thisElement)] from:body"
where thisElement
would be the element that the hx-trigger
is defined on.proud-librarian-99598
04/30/2023, 8:57 AMlet tree = document.getElementById('repositories-tree');
tree.addEventListener('sl-selection-change', event => {
event.detail.selection.forEach(it => {
htmx.trigger(it, 'do-it');
});
});
I am just wondering why I need to pass in an event name. I don't have hx-trigger
on the element itself. I just want to trigger the htmx behaviour. If I do htmx.trigger(it)
, there is a JavaScript error.mysterious-toddler-20573
04/30/2023, 6:13 PMthis
symbol set to the element it is defined onmysterious-toddler-20573
04/30/2023, 6:13 PMmysterious-toddler-20573
04/30/2023, 6:13 PMproud-librarian-99598
04/30/2023, 6:26 PMnumerous-application-19425
05/01/2023, 12:28 AMhx-trigger
custom event
This listens for a HX-Trigger moGetBookmarkButton_ID
event on the div#bookmark_item_*
element to trigger a hx-get
php
kirby()->response()->header('HX-Trigger','moGetBookmarkButton_' . $product->id())
//eg: kirby()->response()->header('HX-Trigger','moGetBookmarkButton_b2')
The HTML in Pug template language to keep it short.
pug
- var values = { a1: 'Item A', b2: 'Item B', d4: 'Item 4' };
each item, id in values
div(id=`bookmark_item_${id}`,hx-get=`bookmark/${id}`,hx-trigger=`moGetBookmarkButton_${id} from:body`)= item
//- eg: div(id=`bookmark_item_b2`,hx-get=`bookmark/b2`,hx-trigger=`moGetBookmarkButton_b2 from:body`)= item
Pro: transparent code, no extra JS
Contra: **How performant is this, in a list of 100 #bookmark_item_*
elements with 100 hx-trigger="moGetBookmarkButton_*"
listening?**
This was my first solution and it seems to work well. I thought about two other solutions, that have drawbacks and become more complex, but are maybe worth to explore. I laid them all out here: https://gist.github.com/marcus-at-localhost/6e235888514fb081b56cc0ee7c72a888
V1 is definitively the most simple solution and probably preferable. What do you think? (I don't know if I can fake HX-Trigger
headers through the demo.htmx.org else I would have build a JsFiddle)mysterious-toddler-20573
05/01/2023, 12:37 AMmysterious-toddler-20573
05/01/2023, 2:36 PMnumerous-application-19425
05/01/2023, 6:13 PMmysterious-toddler-20573
05/01/2023, 6:30 PMjolly-waitress-42858
05/01/2023, 8:09 PMbitter-machine-55943
05/01/2023, 9:25 PMjolly-waitress-42858
05/01/2023, 9:35 PMbitter-machine-55943
05/01/2023, 9:38 PMjolly-waitress-42858
05/01/2023, 9:48 PMbitter-machine-55943
05/01/2023, 10:02 PMnumerous-application-19425
05/02/2023, 1:35 AMHX-Trigger
I'm happy to see improvements. Is there something like a HTMX demo collection (beside the official one)? Here are a few of my demos: https://codepen.io/collection/BNVjqp
https://cdn.discordapp.com/attachments/725789747212976259/1102770304415191131/image.pngโพ
mysterious-toddler-20573
05/02/2023, 3:10 AMhttps://cdn.discordapp.com/attachments/725789747212976259/1102794287290265673/image.pngโพ