htmx-extensions icon indicating copy to clipboard operation
htmx-extensions copied to clipboard

Disable a button while sse connection is active

Open gnituy18 opened this issue 1 year ago • 1 comments

I am trying to disable a button while an SSE connection is actively receiving data. The button, when clicked, requests suggestions generated by an AI. It triggers an SSE connection by retrieving a div element with an hx-ext="sse" attribute.

The hx-disabled-elt attribute does not work for this scenario because the button's action is merely to retrieve the div that initiates the SSE connection.

Is there a proper way to disable the button while the SSE connection is active? Alternatively, is it possible to implement something like an sse-disable-elt attribute?

I am currently using [email protected] and [email protected].

gnituy18 avatar Apr 18 '24 16:04 gnituy18

Hey, to be honest it seems to be that kind of specific-enough situation for me that you'd want to add a little custom JS snippet to handle it. Like adding the disabled attribute on the button when swapping in your SSE element, and removing it on htmx:beforeCleanupElement

Telroshan avatar Jul 10 '24 07:07 Telroshan