Skip to content

Commit

Permalink
target can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
pfiadDi authored and pfiadDi committed Aug 1, 2024
1 parent f010924 commit 8817374
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ var htmx = (function() {
return false
}
if (evt.type === 'submit' || evt.type === 'click') {
if (elt.tagName === 'FORM' && asElement(evt.target).tagName === 'FORM') {
if (elt.tagName === 'FORM' && asElement(evt.target)?.tagName === 'FORM') {
return true
}
if (matches(elt, 'input[type="submit"], button') && closest(elt, 'form') !== null) {
Expand Down
3 changes: 3 additions & 0 deletions test/core/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ describe('Core htmx internals Tests', function() {

htmx._('shouldCancel')({ type: 'click', target: document.createElement('form') }, form).should.equal(true)

// function works also when target isn't an Element
htmx._('shouldCancel')({ type: 'click', target: null }, form).should.equal(false)

var form = make("<form><input id='i1' type='submit'></form>")
var input = byId('i1')
htmx._('shouldCancel')({ type: 'click', target: document.createElement('input') }, input).should.equal(true)
Expand Down

0 comments on commit 8817374

Please sign in to comment.