-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly handle buttons with formmethod=dialog #2753
Conversation
Hey, I'm gonna shamelessly copy-paste the message I left on the other PR, that actually doesn't apply to it but applies here!
|
Perhaps for the purposes of discussion, @SamDudley could chime in here and help us understand the intent of his PR? Given their example below,
Is this supposed to 1) submit the form (via htmx) and then 2) close the dialog (via user agent)? Or something else? |
I completely understand not wanting to break backwards compatibility, and would be willing to add a config value if that's deemed an acceptable path forward. Thanks! |
Hey, it's been awhile since I worked on the project that prompted my PR, but I'll try to recall my intentions. In the project I was working on, I wanted the form to be submitted (via htmx) and then for the dialog to be closed. I seem to recall that closing the dialog required some additional code, so it's possible the example would only submit the form (via htmx) and not close the dialog (testing required). Having read this comment, and looking through the MDN docs myself, I agree that the behaviour I introduced is inconsistent with the MDN docs (and I assume the HTML spec). It's interesting to think about what approach people would expect Either way, personally I have no issues with this PR changing the behaviour to be consistent with the HTML spec, however in the interest of maintaining backwards compatibility, making the behaviour opt-in seems like the most sensible approach. |
Just spitballing here, but it seems to me like the "correct" way to submit a form (via hx-post) and then close the dialog would be to do something like
This way people who use HTMX as progressive enhancement only can still have nice no-js behavior:
|
We ran into this today and assumed the opposite behavior would happen:
htmx's current behavior makes sense to me on reflection, because formmethod is overriding the native method and not the hx-post attribute, after all. However, boosted forms complicate it somewhat. We were able to resolve this for our use case by adding an ID and an explicit trigger pointing to the submit button, like:
What I was thinking would be nice is a way to tell htmx that a button should be ignored:
That way, we wouldn't need to complicate the ID namespace. |
Description
Buttons with
formmethod
specified should only be handled by HTMX if the value is an HTTP verb. This partially addresses Issue #2554 (along with PR #2752) and (imho) fixes the behavior introduced in PR #1867. If a button withformmethod="dialog"
is a clicked, HTMX should ignore the request and let the browser handle closing the dialog (see this comment).Testing
I removed two ajax tests added by PR #2752 (that were also duplicated in the shadowdom tests) and replaced them with a test that should be checking that the server had no response. The tests passed but I'm not 100% the test were correctly written.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded