_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

toggle <something> until <event> at last <timeout>

Open vlcinsky opened this issue 4 years ago • 2 comments
trafficstars

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.

vlcinsky avatar Aug 04 '21 11:08 vlcinsky

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 avatar Aug 04 '21 16:08 1cg

@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.

vlcinsky avatar Aug 23 '21 09:08 vlcinsky