Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3389,8 +3389,10 @@ var htmx = (function() {
forEach(disabledElts, function(disabledElement) {
const internalData = getInternalData(disabledElement)
internalData.requestCount = (internalData.requestCount || 0) + 1
disabledElement.setAttribute('disabled', '')
disabledElement.setAttribute('data-disabled-by-htmx', '')
if (!disabledElement.hasAttribute('disabled')) {
disabledElement.setAttribute('disabled', '')
disabledElement.setAttribute('data-disabled-by-htmx', '')
}
})
return disabledElts
}
Expand All @@ -3412,7 +3414,7 @@ var htmx = (function() {
})
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.

disabledElement.removeAttribute('disabled')
disabledElement.removeAttribute('data-disabled-by-htmx')
}
Expand Down
12 changes: 12 additions & 0 deletions test/attributes/hx-disabled-elt.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ describe('hx-disabled-elt attribute', function() {
fieldset.hasAttribute('disabled').should.equal(false)
})

it('preserve pre-disabled elements', function() {
this.server.respondWith('GET', '/test', 'ok')
const b1 = make('<button hx-get="/test" hx-disabled-elt="#b2">Click Me!</button>')
const b2 = make('<button id="b2" disabled></button>')
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.

this.server.respond()
b2.hasAttribute('disabled').should.equal(true)
})

it('multiple requests with same disabled elt are handled properly', function() {
this.server.respondWith('GET', '/test', 'Clicked!')
var b1 = make('<button hx-get="/test" hx-disabled-elt="#b3">Click Me!</button>')
Expand Down