Skip to content

Commit

Permalink
fix bug where naked hx-triggers caused boosted forms w/ explicit `h…
Browse files Browse the repository at this point in the history
…x-trigger`s to not fire
  • Loading branch information
1cg committed Apr 26, 2023
1 parent d3d5155 commit 8708fe2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1739,13 +1739,6 @@ return (function () {
});
}
});
if (!explicitAction && hasAttribute(elt, 'hx-trigger')) {
explicitAction = true
triggerSpecs.forEach(function(triggerSpec) {
// For "naked" triggers, don't do anything at all
addTriggerHandler(elt, triggerSpec, nodeData, function () { })
})
}
return explicitAction;
}

Expand Down Expand Up @@ -1930,10 +1923,18 @@ return (function () {
}

var triggerSpecs = getTriggerSpecs(elt);
var explicitAction = processVerbs(elt, nodeData, triggerSpecs);

if (!explicitAction && getClosestAttributeValue(elt, "hx-boost") === "true") {
boostElement(elt, nodeData, triggerSpecs);
var hasExplicitHttpAction = processVerbs(elt, nodeData, triggerSpecs);

if (!hasExplicitHttpAction) {
if (getClosestAttributeValue(elt, "hx-boost") === "true") {
boostElement(elt, nodeData, triggerSpecs);
} else if (hasAttribute(elt, 'hx-trigger')) {
triggerSpecs.forEach(function (triggerSpec) {
// For "naked" triggers, don't do anything at all
addTriggerHandler(elt, triggerSpec, nodeData, function () {
})
})
}
}

if (elt.tagName === "FORM") {
Expand Down
11 changes: 10 additions & 1 deletion test/attributes/hx-boost.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe("hx-boost attribute", function() {

htmx.logAll();
beforeEach(function () {
this.server = makeServer();
clearWorkArea();
Expand All @@ -20,7 +21,6 @@ describe("hx-boost attribute", function() {


it('handles basic form post properly', function () {
this.server.respondWith("POST", "/test", "Boosted");
this.server.respondWith("POST", "/test", "Boosted");
var div = make('<div hx-target="this" hx-boost="true"><form id="f1" action="/test" method="post"><button id="b1">Submit</button></form></div>');
var btn = byId('b1');
Expand All @@ -29,6 +29,15 @@ describe("hx-boost attribute", function() {
div.innerHTML.should.equal("Boosted");
})

it('handles basic form post properly w/ explicit action', function () {
this.server.respondWith("POST", "/test", "Boosted");
var div = make('<div hx-target="this"><form id="f1" action="/test" method="post" hx-trigger="click" hx-boost="true"></form></div>');
var form = byId('f1');
form.click();
this.server.respond();
div.innerHTML.should.equal("Boosted");
})

it('handles basic form get properly', function () {
this.server.respondWith("GET", "/test", "Boosted");
var div = make('<div hx-target="this" hx-boost="true"><form id="f1" action="/test" method="get"><button id="b1">Submit</button></form></div>');
Expand Down

0 comments on commit 8708fe2

Please sign in to comment.