Merge branch 'pull/388' into dev

This commit is contained in:
carson 2021-02-27 17:45:16 -07:00
commit e0decc9a19
2 changed files with 21 additions and 1 deletions

View File

@ -925,7 +925,7 @@ return (function () {
function shouldCancel(elt) {
return elt.tagName === "FORM" ||
(matches(elt, 'input[type="submit"], button') && closest(elt, 'form') !== null) ||
(elt.tagName === "A" && elt.href && elt.href.indexOf('#') !== 0);
(elt.tagName === "A" && elt.href && elt.getAttribute('href').indexOf('#') !== 0);
}
function ignoreBoostedAnchorCtrlClick(elt, evt) {

View File

@ -41,4 +41,24 @@ describe("Core htmx internals Tests", function() {
chai.expect(htmx._("tokenizeString")("aa.aa")).to.be.deep.equal(['aa', '.', 'aa']);
})
it("tags respond correctly to shouldCancel", function() {
var anchorThatShouldCancel = make("<a href='/foo'></a>");
htmx._("shouldCancel")(anchorThatShouldCancel).should.equal(true);
var anchorThatShouldNotCancel = make("<a href='#'></a>");
htmx._("shouldCancel")(anchorThatShouldNotCancel).should.equal(false);
var form = make("<form></form>");
htmx._("shouldCancel")(form).should.equal(true);
var form = make("<form><input id='i1' type='submit'></form>");
var input = byId("i1");
htmx._("shouldCancel")(input).should.equal(true);
var form = make("<form><button id='b1' type='submit'></form>");
var button = byId("b1");
htmx._("shouldCancel")(button).should.equal(true);
})
});