Skip to content

Commit

Permalink
Add missing htmx:trigger event on load triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpetros committed Nov 24, 2024
1 parent bc7ea4a commit a5c5de9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,7 @@ var htmx = (function() {
const load = function() {
if (!nodeData.loaded) {
nodeData.loaded = true
triggerEvent(elt, 'htmx:trigger')
handler(elt)
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/attributes/hx-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,28 @@ describe('hx-trigger attribute', function() {
}, 50)
})

it('fires the htmx:trigger event when the trigger is a load', function(done) {
this.server.respondWith(
'GET',
'/test',
'<div hx-trigger="load delay:50ms" hx-on::trigger="this.innerText = \'Done\'">Response</div>'
)

var div = make('<div hx-get="/test">Submit</div>')
div.click()
this.server.respond()
var response = div.children[0]
response.innerText.should.equal('Response')

setTimeout(function() {
try {
response.innerText.should.equal('Done')
done()
} finally {
}
}, 100)
})

it('filters support "this" reference to the current element', function() {
this.server.respondWith('GET', '/test', 'Called!')
var form = make('<form hx-get="/test" hx-trigger="click[this.classList.contains(\'bar\')]">Not Called</form>')
Expand Down

0 comments on commit a5c5de9

Please sign in to comment.