Enforce no-op on submit buttons with formmethod=dialog. #3075
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
In Oct 2023, PR #1867 introduced a possible antipattern:
As a result of the above PR, current behavior is that clicking the button closes the dialog and submits the form (via hx-post). This is contrary to MDN docs on
formmethod=dialog
.The author of that PR has since supported changing the behavior he introduced.
IMO people wishing to close a dialog and submit a form via HTMX at the same time should use e.g.
hx-on:htmx:after-swap="event.target.closest('dialog').close()
.There is a bit more conversation at PR #2753, which was my first attempt at this (PR was deleted because I couldn't git gud). Carson has approved this approach.
Corresponding issue: #1866
Testing
I have remove two tests and implemented one that I believe fits this situation, but I would appreciate it if someone could carefully review my test since I'm 100% on how the testing internals work.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded