_hyperscript
_hyperscript copied to clipboard
toggle <something> until <event> at last <timeout>
Typical usage of toggle is to disable a button on a click until a response is loaded, e.g.:
on click toggle [@disabled=true] until htmx:afterOnLoad
In case a response fails somehow, the button remains disabled.
I would invite some sort of timeout option which would toggle back either on an event or at given timeout, whatever comes sooner.
E.g.:
on click toggle [@disabled=true] until htmx:afterOnLoad at last in 5s
or explain me, how it can be done today.
Hi @vlcinsky
Maybe the htmx:afterRequest event would be better? https://htmx.org/events/#htmx:afterRequest
That should be fired no matter what.
I'd like to add general command timeout functionality, but it is quite tricky to implement.
@1cg the htmx:afterRequest fires either when some response is received (this is not my issue) or when the network fails. The later might be a bit too late, typically it cold last like 30 seconds or even longer.
One option would be to control the timeouts before the request is sent, that way we would not have lingering requests which after some timeout nobody cares about.
Having general command timeout would be very handy and would probably solve my use case. Good luck with finding proper comand timeout solution.