Skip to content

Commit

Permalink
Include #2915 fix
Browse files Browse the repository at this point in the history
Co-Authored-By: MichaelWest22 <[email protected]>
  • Loading branch information
Telroshan and MichaelWest22 committed Sep 19, 2024
1 parent b6022a3 commit c429e92
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,29 +1155,34 @@ var htmx = (function() {
selector = selector.substring(7)
}

let item
if (selector.indexOf('closest ') === 0) {
result.push(closest(asElement(elt), normalizeSelector(selector.substr(8))))
item = closest(asElement(elt), normalizeSelector(selector.substr(8)))
} else if (selector.indexOf('find ') === 0) {
result.push(find(asParentNode(elt), normalizeSelector(selector.substr(5))))
item = find(asParentNode(elt), normalizeSelector(selector.substr(5)))
} else if (selector === 'next' || selector === 'nextElementSibling') {
result.push(asElement(elt).nextElementSibling)
item = asElement(elt).nextElementSibling
} else if (selector.indexOf('next ') === 0) {
result.push(scanForwardQuery(elt, normalizeSelector(selector.substr(5)), global))
item = scanForwardQuery(elt, normalizeSelector(selector.substr(5)), global)
} else if (selector === 'previous' || selector === 'previousElementSibling') {
result.push(asElement(elt).previousElementSibling)
item = asElement(elt).previousElementSibling
} else if (selector.indexOf('previous ') === 0) {
result.push(scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)), global))
item = scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)), global)
} else if (selector === 'document') {
result.push(document)
item = document
} else if (selector === 'window') {
result.push(window)
item = window
} else if (selector === 'body') {
result.push(document.body)
item = document.body
} else if (selector === 'root') {
result.push(getRootNode(elt, global))
item = getRootNode(elt, global)
} else {
unprocessedParts.push(selector)
}

if (item) {
result.push(item)
}
}

if (unprocessedParts.length > 0) {
Expand Down
22 changes: 21 additions & 1 deletion test/attributes/hx-disabled-elt.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('hx-disabled-elt attribute', function() {
b3.hasAttribute('disabled').should.equal(false)
})

it('find on multiple elts can be disabled', function() {
it('hx-disabled-elt supports multiple extended selectors', function() {
this.server.respondWith('GET', '/test', 'Clicked!')
var form = make('<form hx-get="/test" hx-disabled-elt="find input[type=\'text\'], find button" hx-swap="none"><input id="i1" type="text" placeholder="Type here..."><button id="b2" type="submit">Send</button></form>')
var i1 = byId('i1')
Expand All @@ -99,4 +99,24 @@ describe('hx-disabled-elt attribute', function() {
i1.hasAttribute('disabled').should.equal(false)
b2.hasAttribute('disabled').should.equal(false)
})

it('closest/find/next/previous handle nothing to find without exception', function() {
this.server.respondWith('GET', '/test', 'Clicked!')
var btn1 = make('<button hx-get="/test" hx-disabled-elt="closest input">Click Me!</button>')
var btn2 = make('<button hx-get="/test" hx-disabled-elt="find input">Click Me!</button>')
var btn3 = make('<button hx-get="/test" hx-disabled-elt="next input">Click Me!</button>')
var btn4 = make('<button hx-get="/test" hx-disabled-elt="previous input">Click Me!</button>')
btn1.click()
btn1.hasAttribute('disabled').should.equal(false)
this.server.respond()
btn2.click()
btn2.hasAttribute('disabled').should.equal(false)
this.server.respond()
btn3.click()
btn3.hasAttribute('disabled').should.equal(false)
this.server.respond()
btn4.click()
btn4.hasAttribute('disabled').should.equal(false)
this.server.respond()
})
})

0 comments on commit c429e92

Please sign in to comment.