Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response-targets doesn't reset htmx-request class if hx-disabled-elt is used #79

Open
craigharman opened this issue Aug 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@craigharman
Copy link
Contributor

craigharman commented Aug 15, 2024

If you have an element that uses hx-target-error and hx-disabled-elt and get an error response back htmx-request class doesn't get removed. It does if you remove hx-disabled-elt.

eg. This keeps .htmx-request class on elements:

<form hx-post="/tip" hx-target="#targetDiv" hx-swap="outerHTML swap:1s show:top" hx-trigger="click" hx-target-error="#showError" hx-disabled-elt="this">

While this removes them:

<form hx-post="/tip" hx-target="#targetDiv" hx-swap="outerHTML swap:1s show:top" hx-trigger="click" hx-target-error="#showError">

@Telroshan
Copy link
Collaborator

Hey, took a quick look, it seems that both disableElements and addRequestIndicatorClasses in the core, increment an internal requestCount property, and remove their associated classes when that count reaches 0.

I would guess that the issue is, since removeRequestIndicators processes the indicators (thus htmx-request) first, for an element that has both attributes, as for a single request the count will be 2 (as indicator + disable-elt incremented it), the count is 1 when decrementing and processing htmx-request, in which case the class is not removed (check is against a 0 value), then the disabled attribute is properly removed as the count reaches 0.

Didn't spend more time than this so there might be more to it, but if you feel like investigating, a bugfix PR would be welcome!
I suspect this could even be a problem with the lib itself (with that double count thing) and not the extension, but this needs confirmation!

@Telroshan Telroshan added the bug Something isn't working label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants