Skip to content

Commit

Permalink
Do not boost forms with method="dialog" (#2752)
Browse files Browse the repository at this point in the history
* Do not boost forms with method="dialog"

* Clean up
  • Loading branch information
pokonski authored Aug 5, 2024
1 parent 941e94f commit ee9b0e0
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -2277,7 +2277,7 @@ var htmx = (function() {
* @param {HtmxTriggerSpecification[]} triggerSpecs
*/
function boostElement(elt, nodeData, triggerSpecs) {
if ((elt instanceof HTMLAnchorElement && isLocalLink(elt) && (elt.target === '' || elt.target === '_self')) || elt.tagName === 'FORM') {
if ((elt instanceof HTMLAnchorElement && isLocalLink(elt) && (elt.target === '' || elt.target === '_self')) || (elt.tagName === 'FORM' && String(getRawAttribute(elt, 'method')).toLowerCase() !== 'dialog')) {
nodeData.boosted = true
let verb, path
if (elt.tagName === 'A') {
Expand Down
8 changes: 8 additions & 0 deletions test/attributes/hx-boost.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ describe('hx-boost attribute', function() {
div.innerHTML.should.equal('Boosted')
})

it('does not boost forms with method="dialog"', function() {
make('<div hx-boost="true"><form id="f1" action="/test" method="dialog"><button id="b1">close</button></form></div>')
var form = byId('f1')

var internalData = htmx._('getInternalData')(form)
should.equal(undefined, internalData.boosted)
})

it('handles basic anchor properly w/ data-* prefix', function() {
this.server.respondWith('GET', '/test', 'Boosted')
var div = make('<div data-hx-target="this" data-hx-boost="true"><a id="a1" href="/test">Foo</a></div>')
Expand Down

0 comments on commit ee9b0e0

Please sign in to comment.