Submitting a form using GET: discrepancy between htmx and browser#3694
Open
ergor wants to merge 1 commit intobigskysoftware:devfrom
Open
Submitting a form using GET: discrepancy between htmx and browser#3694ergor wants to merge 1 commit intobigskysoftware:devfrom
ergor wants to merge 1 commit intobigskysoftware:devfrom
Conversation
Given this form:
<form action="/test" method="get">
<input type="hidden" name="action" value="A">
<button id="btnB" type="submit" name="action" value="B">B</button>
</form>
When clicking the button,
The browser's behavior is to _append_ both values, resulting in a query
string as "action=A&action=B".
But, when using HTMX, given this form:
<form hx-get="/test">
<input type="hidden" name="action" value="A">
<button id="btnB" type="submit" name="action" value="B">B</button>
</form>
When clicking the button,
HTMX issues a GET request, where the button's value _overrides_ any
other form data. This is _unexpected_ behavior.
This patch tries to bring HTMX in line with default browser behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Given this form:
When clicking the button,
The browser's behavior is to append both values, resulting in a query string as "action=A&action=B".
But, when using HTMX, given this form:
When clicking the button,
HTMX issues a GET request, where the button's value overrides any other form data with the same
name; the resulting query string is just "action=B". This is unexpected behavior.This patch tries to bring HTMX in line with default browser behavior.
Now, I think this solution is rather hacky. Why is there differentiation between GET and non-GET requests in
getInputValues()in the first place? I don't know the intricacies of HTMX, explanations are appreciated. I am open to iterate on this PR if the solution is below quality expectation.Corresponding issue:
#1541
This issue brought it up, but was then closed due to #1559. However, that PR didn't fix it for the case of
GET.Testing
I tested it using the test suite. I added relevant test-cases that triggered the bug, and then verified the fix by running the tests with
npm run testChecklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded