From a4412db6be76c1547e78c0f0eaf47f2a3d108520 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Wed, 24 Feb 2021 21:07:32 -0600 Subject: [PATCH 1/2] Use getAttribute("href") instead of .href #385 --- src/htmx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/htmx.js b/src/htmx.js index 401e9361..a261cda3 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -922,7 +922,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) { From 74c4abe1be97550477ef281c71ed972798f40327 Mon Sep 17 00:00:00 2001 From: carson Date: Sat, 27 Feb 2021 17:43:58 -0700 Subject: [PATCH 2/2] add test for shouldCancel() contribution by Bo Peng --- test/core/internals.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/core/internals.js b/test/core/internals.js index 1af2293c..e9513420 100644 --- a/test/core/internals.js +++ b/test/core/internals.js @@ -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(""); + htmx._("shouldCancel")(anchorThatShouldCancel).should.equal(true); + + var anchorThatShouldNotCancel = make(""); + htmx._("shouldCancel")(anchorThatShouldNotCancel).should.equal(false); + + var form = make("
"); + htmx._("shouldCancel")(form).should.equal(true); + + var form = make("
"); + var input = byId("i1"); + htmx._("shouldCancel")(input).should.equal(true); + + var form = make("