Skip to content

Commit

Permalink
Better graceful degradation of boosted form element (#2802)
Browse files Browse the repository at this point in the history
* better graceful degradation of form elt

* smaller

* move fix and add tests
  • Loading branch information
NDoolan360 authored Oct 3, 2024
1 parent c24adef commit 8c65826
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2316,9 +2316,10 @@ var htmx = (function() {
} else {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
if (verb === 'get') {
}
path = getRawAttribute(elt, 'action')
if (verb === 'get' && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
triggerSpecs.forEach(function(triggerSpec) {
addEventListener(elt, function(node, evt) {
Expand Down
25 changes: 25 additions & 0 deletions test/attributes/hx-boost.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,29 @@ describe('hx-boost attribute', function() {
this.server.respond()
btn.innerHTML.should.equal('Boosted!')
})

it('form get w/ search params in action property excludes search params', function() {
this.server.respondWith('GET', /\/test.*/, function(xhr) {
should.equal(undefined, getParameters(xhr).foo)
xhr.respond(200, {}, 'Boosted!')
})

var div = make('<div hx-target="this" hx-boost="true"><form id="f1" action="/test?foo=bar" method="get"><button id="b1">Submit</button></form></div>')
var btn = byId('b1')
btn.click()
this.server.respond()
div.innerHTML.should.equal('Boosted!')
})

it('form post w/ query params in action property uses full url', function() {
this.server.respondWith('POST', /\/test.*/, function(xhr) {
should.equal(undefined, getParameters(xhr).foo)
xhr.respond(200, {}, 'Boosted!')
})
var div = make('<div hx-target="this" hx-boost="true"><form id="f1" action="/test?foo=bar" method="post"><button id="b1">Submit</button></form></div>')
var btn = byId('b1')
btn.click()
this.server.respond()
div.innerHTML.should.equal('Boosted!')
})
})

0 comments on commit 8c65826

Please sign in to comment.