gorgeous-iron-50959
01/23/2021, 12:00 AM<i id="refreshAcct1" class="bi-list has-pointer icon-button" title="view messages" hx-get="/messages/view/1" hx-trigger="click, refreshAcct1" hx-target="#messages-target"></i>
Then I've got this as my trigger php header
HX-Trigger: {"togglepanel":"","refreshAcct1":""}
The click event on the topic works fine. The togglepanel just closes the edit panel and reopens the messages-target div. The refreshAcct1 doesn't work. I'm not great with event stuff so probably something I'm not doing right?most-jelly-15242
01/23/2021, 12:21 AM<i> tag, so it doesn't catch the event. Per the docs https://htmx.org/headers/x-hx-trigger/ If that's the case, you need to add an event listener that triggers the event on the tag using the htmx.trigger api method https://htmx.org/api/#trigger. This is just a wild guess.most-jelly-15242
01/23/2021, 12:25 AMjs
document.body.addEventListener("updateAcct1", function(evt){
htmx.trigger(htmx.find("#refreshAcct1"), 'refreshAcct1');
})
And in HX-Trigger, use updateAcct1 instead of refreshAcct1 because I am not sure if you'll get into an infinite loop otherwise.mysterious-toddler-20573
01/23/2021, 1:23 AM#refreshAcct1 isn't in the hierarchy to get that message. A couple of ideas:
1 - Generalize the event to something like refreshElement and pass down the account id, so you could write logic like this:
HX-Trigger: {"updateAccount": {"account" : accountString}}
js
document.body.addEventListener("updateAccount", function(evt){
var accountStr = evt.detail.account;
htmx.trigger(htmx.find("#refresh" + accountStr), 'refresh' + accountStr);
})mysterious-toddler-20573
01/23/2021, 1:24 AMfrom modifier in triggers:
https://htmx.org/attributes/hx-trigger/mysterious-toddler-20573
01/23/2021, 1:25 AMhtml
<i id="refreshAcct1"
class="bi-list has-pointer icon-button"
title="view messages"
hx-get="/messages/view/1"
hx-trigger="click, refreshAcct1 from:body"
hx-target="#messages-target"></i>mysterious-toddler-20573
01/23/2021, 1:26 AMmysterious-toddler-20573
01/23/2021, 1:26 AMgorgeous-iron-50959
01/23/2021, 2:19 AMgorgeous-iron-50959
01/23/2021, 1:49 PMmysterious-toddler-20573
01/23/2021, 2:38 PMgorgeous-iron-50959
01/23/2021, 3:33 PMmysterious-toddler-20573
01/24/2021, 3:41 AMmysterious-toddler-20573
01/24/2021, 3:42 AMgorgeous-ghost-95789
01/24/2021, 3:48 AMgorgeous-ghost-95789
01/24/2021, 3:49 AMbig-airline-13935
01/24/2021, 11:01 AMfamous-salesclerk-78204
01/24/2021, 11:35 AMmysterious-toddler-20573
01/24/2021, 3:17 PMhx-get to retrieve itfamous-salesclerk-78204
01/24/2021, 3:17 PMmysterious-toddler-20573
01/24/2021, 3:18 PMmysterious-toddler-20573
01/24/2021, 3:19 PMsparse-musician-64201
01/25/2021, 6:44 PMsparse-musician-64201
01/25/2021, 6:45 PMmysterious-toddler-20573
01/25/2021, 6:52 PMsparse-musician-64201
01/25/2021, 7:17 PMsparse-musician-64201
01/25/2021, 7:19 PMthankful-addition-60522
01/26/2021, 1:27 PMmysterious-toddler-20573
01/26/2021, 2:22 PMthankful-addition-60522
01/26/2021, 2:34 PM