Skip to content

Commit 31430d9

Browse files
Include target selector in htmx:oobErrorNoTarget event and error log (#3644)
1 parent a5fd180 commit 31430d9

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/htmx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ var htmx = (function() {
15081508
oobElement.parentNode.removeChild(oobElement)
15091509
} else {
15101510
oobElement.parentNode.removeChild(oobElement)
1511-
triggerErrorEvent(getDocument().body, 'htmx:oobErrorNoTarget', { content: oobElement })
1511+
triggerErrorEvent(getDocument().body, 'htmx:oobErrorNoTarget', { content: oobElement, target: selector })
15121512
}
15131513
return oobValue
15141514
}
@@ -3111,7 +3111,7 @@ var htmx = (function() {
31113111
htmx.logger(elt, eventName, detail)
31123112
}
31133113
if (detail.error) {
3114-
logError(detail.error)
3114+
logError(detail.error + (detail.target ? ', ' + detail.target : ''))
31153115
triggerEvent(elt, 'htmx:error', { errorInfo: detail })
31163116
}
31173117
let eventResult = elt.dispatchEvent(event)

test/attributes/hx-swap-oob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ describe('hx-swap-oob attribute', function() {
348348
})
349349
}
350350

351-
it.skip('triggers htmx:oobErrorNoTarget when no targets found', function(done) {
352-
// this test fails right now because when targets not found it returns an empty array which makes it miss the event as it should be if (targets.length)
351+
it('triggers htmx:oobErrorNoTarget when no targets found', function(done) {
353352
this.server.respondWith('GET', '/test', "Clicked<div id='nonexistent' hx-swap-oob='true'>Swapped</div>")
354353
var div = make('<div hx-get="/test">click me</div>')
355354

356355
// Define the event listener function so it can be removed later
357356
var eventListenerFunction = function(event) {
358357
event.detail.content.innerHTML.should.equal('Swapped')
358+
event.detail.target.should.equal('#nonexistent')
359359
document.body.removeEventListener('htmx:oobErrorNoTarget', eventListenerFunction)
360360
done()
361361
}

www/content/events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ in the DOM to switch with.
384384
##### Details
385385

386386
* `detail.content` - the element with the bad oob `id`
387+
* `detail.target` - the bad CSS selector
387388

388389
### Event - `htmx:onLoadError` {#htmx:onLoadError}
389390

0 commit comments

Comments
 (0)