proud-librarian-99598
10/03/2021, 8:13 AMsparse-musician-64201
10/03/2021, 11:04 AMsparse-musician-64201
10/03/2021, 11:05 AMproud-librarian-99598
10/03/2021, 12:03 PMenough-bear-62625
10/03/2021, 1:30 PM<div hx-get="/activity" hx-trigger="every 60s"></div>
But I'd also like a way to turn it off and back on. Ideally an icon that you click that stops or starts polling as well as switching the icon itself to indicate whether it is polling or not. If that doesn't work, just a checkbox would work. It seems like all the parts are there but I'm not sure how to put them together. Is something like this possible and simple? FYI - I'm a DBA dabbling in the front-end world.mysterious-toddler-20573
10/03/2021, 3:01 PMhtml
<div hx-get="/activity" hx-trigger="every 60s[pollingEnabled]">
</div>
And then set a global variable via javascript or hyperscript:
html
<script>
window.pollingEnabled = true;
</script>
<button onClick="window.pollingEnabled = true">Enable Polling</button>
<button onClick="window.pollingEnabled = false">Disable Polling</button>mysterious-toddler-20573
10/03/2021, 3:07 PMhtml
<div id="polling-div"
hx-get="/activity" hx-trigger="fetch"
_="init repeat forever
wait 60s then
trigger fetch unless @data-paused is 'true'">
...
</div>
<button _="on click set the #polling-div's @data-paused to false">
Enable Polling
</button>
<button _="on click set the #polling-div's @data-paused to true">
Enable Polling
</button>gorgeous-airport-54386
10/03/2021, 3:07 PMs/@disabled/@data-paused/gorgeous-airport-54386
10/03/2021, 3:08 PM@ means anything in regexmysterious-toddler-20573
10/03/2021, 3:10 PMenough-bear-62625
10/03/2021, 3:10 PMmysterious-toddler-20573
10/03/2021, 3:26 PMmysterious-toddler-20573
10/03/2021, 3:26 PMmysterious-toddler-20573
10/03/2021, 3:35 PMmysterious-toddler-20573
10/03/2021, 4:26 PMhtml
<div id="polling-div"
hx-target="this" hx-swap="outerHTML"
hx-get="/activity" hx-trigger="every 60s">
<button hx-get="/activity/start">Start Polling</button>
<button hx-get="/activity/stop">Stop Polling</button>
</div>
where the /activity/start and /activity/stop end points render pretty much the same thing as activity, but with the hx-trigger included or omitted.mysterious-toddler-20573
10/03/2021, 4:27 PMmysterious-toddler-20573
10/03/2021, 4:27 PMenough-bear-62625
10/03/2021, 5:02 PMlemon-carpenter-66863
10/03/2021, 5:49 PMmysterious-toddler-20573
10/03/2021, 7:48 PMlemon-carpenter-66863
10/03/2021, 7:53 PMmysterious-toddler-20573
10/03/2021, 7:59 PMmysterious-toddler-20573
10/03/2021, 7:59 PMmysterious-toddler-20573
10/03/2021, 8:00 PMmysterious-toddler-20573
10/03/2021, 8:00 PMhx-preserve which will preserve an element by ID: https://htmx.org/attributes/hx-preserve/lemon-carpenter-66863
10/03/2021, 8:02 PMmysterious-toddler-20573
10/03/2021, 10:50 PMhx-boost on the body will workmysterious-toddler-20573
10/03/2021, 10:50 PMmysterious-toddler-20573
10/03/2021, 10:51 PMmysterious-toddler-20573
10/03/2021, 10:51 PM