Skip to content

Commit 8c65826

Browse files
authored
Better graceful degradation of boosted form element (#2802)
* better graceful degradation of form elt * smaller * move fix and add tests
1 parent c24adef commit 8c65826

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/htmx.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,9 +2316,10 @@ var htmx = (function() {
23162316
} else {
23172317
const rawAttribute = getRawAttribute(elt, 'method')
23182318
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
2319-
if (verb === 'get') {
2320-
}
23212319
path = getRawAttribute(elt, 'action')
2320+
if (verb === 'get' && path.includes('?')) {
2321+
path = path.replace(/\?[^#]+/, '')
2322+
}
23222323
}
23232324
triggerSpecs.forEach(function(triggerSpec) {
23242325
addEventListener(elt, function(node, evt) {

test/attributes/hx-boost.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,29 @@ describe('hx-boost attribute', function() {
118118
this.server.respond()
119119
btn.innerHTML.should.equal('Boosted!')
120120
})
121+
122+
it('form get w/ search params in action property excludes search params', function() {
123+
this.server.respondWith('GET', /\/test.*/, function(xhr) {
124+
should.equal(undefined, getParameters(xhr).foo)
125+
xhr.respond(200, {}, 'Boosted!')
126+
})
127+
128+
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>')
129+
var btn = byId('b1')
130+
btn.click()
131+
this.server.respond()
132+
div.innerHTML.should.equal('Boosted!')
133+
})
134+
135+
it('form post w/ query params in action property uses full url', function() {
136+
this.server.respondWith('POST', /\/test.*/, function(xhr) {
137+
should.equal(undefined, getParameters(xhr).foo)
138+
xhr.respond(200, {}, 'Boosted!')
139+
})
140+
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>')
141+
var btn = byId('b1')
142+
btn.click()
143+
this.server.respond()
144+
div.innerHTML.should.equal('Boosted!')
145+
})
121146
})

0 commit comments

Comments
 (0)