Skip to content

Conversation

StabbarN
Copy link

Description

Elements with hx-disabled-elt that were already disabled before sending request will now keep the disabled attribute after server has responded or timed out.

A good chunk of the users are probably thinking that this doesn't matter because their html will always swap after request has completed but if they have set htmx.config.timeout the request can time out and elements that are supposed to be disabled will not be disabled anymore.

The attribute data-disabled-by-htmx isn't set if the element already was disabled.

Questions

Should I add a note to the documentation https://htmx.org/attributes/hx-disabled-elt/? Something like "Already disabled elements will not be affected"?

Corresponding issue: #3437

Testing

Test added: preserve pre-disabled elements.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

forEach(disabled, function(disabledElement) {
const internalData = getInternalData(disabledElement)
if (internalData.requestCount === 0) {
if (internalData.requestCount === 0 && disabledElement.hasAttribute('data-disabled-by-htmx')) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test multiple requests with same disabled elt are handled properly will fail without this change.

b2.hasAttribute('disabled').should.equal(true)
b2.hasAttribute('data-disabled-by-htmx').should.equal(false)
b1.click()
b2.hasAttribute('disabled').should.equal(true)
Copy link
Author

@StabbarN StabbarN Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: verify that data-disabled-by-htmx isn't set? That is, adding a line b2.hasAttribute('data-disabled-by-htmx').should.equal(false).
However, data-disabled-by-htmx isn't tested anywhere in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant