mysterious-toddler-20573
09/05/2021, 9:21 PMable-zebra-49180
09/05/2021, 9:22 PMmysterious-toddler-20573
09/05/2021, 9:24 PMhx-select='body'mysterious-toddler-20573
09/05/2021, 9:24 PMmysterious-toddler-20573
09/05/2021, 9:24 PMmysterious-toddler-20573
09/05/2021, 9:25 PMable-zebra-49180
09/05/2021, 9:25 PMmysterious-toddler-20573
09/05/2021, 9:25 PMmysterious-toddler-20573
09/05/2021, 9:26 PMable-zebra-49180
09/05/2021, 9:26 PMmysterious-toddler-20573
09/05/2021, 9:26 PMmysterious-toddler-20573
09/05/2021, 9:26 PMable-zebra-49180
09/05/2021, 9:26 PMable-zebra-49180
09/05/2021, 9:28 PMable-zebra-49180
09/05/2021, 9:28 PMable-zebra-49180
09/05/2021, 9:43 PMable-zebra-49180
09/05/2021, 9:43 PMable-zebra-49180
09/05/2021, 10:58 PMable-zebra-49180
09/05/2021, 11:00 PMmysterious-toddler-20573
09/06/2021, 12:43 AMhx-swap="innerHTML show:none"mysterious-toddler-20573
09/06/2021, 12:45 AM[data-hx-get isn't closed properlymysterious-toddler-20573
09/06/2021, 12:46 AMgorgeous-ghost-95789
09/06/2021, 1:30 AMgorgeous-ghost-95789
09/06/2021, 1:30 AMproud-librarian-99598
09/06/2021, 6:12 AMhtmx.on("htmx:afterRequest", function(evt) {
let input = document.getElementById('new-todo-input');
if( input === evt.detail.elt) {
evt.detail.elt.value = '';
}
});
But I wonder if there is a way to bind to the htmx:afterRequest event of the new-todo-input element directly to avoid the if statement in the function?proud-librarian-99598
09/06/2021, 6:18 AM<span> that shows the number of todo items and it should trigger a new GET request to update when an item is added or when an item is removed. I tried this:
<span th:fragment="active-items-count"
class="todo-count"
hx-get="/htmx-events/active-items-count"
hx-trigger="itemAdded itemDeleted from:body">
<strong th:text="${numberOfActiveItems}">0</strong> item(s) left
</span>
But that does not work. I can get it to work for itemAdded only, or for itemDeleted only if only add one of the 2 in hx-trigger. Is there a way to make it work, or should I file a feature request on GitHub?proud-librarian-99598
09/06/2021, 6:25 AMhtmx.on('#new-todo-input', 'htmx:afterRequest', function (evt) {
evt.detail.elt.value = '';
});proud-librarian-99598
09/06/2021, 6:31 AMhx-trigger="itemAdded from:body" on the HTML
2) Add this JavaScript:
document.body.addEventListener('itemDeleted', function (evt) {
let el = document.getElementById('active-items-count');
htmx.trigger(el, 'itemAdded');
});
So basically, take the itemDeleted event (that arrives via HX-Trigger header from the server) and send an itemAdded event on the element to trigger the hx-get that updates the span.
I am open for better suggestions πrough-river-58405
09/06/2021, 10:15 AMproud-librarian-99598
09/06/2021, 10:16 AM