Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngForm): don't block submit when method=dialog #12882

Open
wants to merge 1 commit into
base: v1.4.x
Choose a base branch
from

Conversation

dpogue
Copy link

@dpogue dpogue commented Sep 18, 2015

When a form's method is set to "dialog" it does not post to a server but instead closes the nearest parent element. An action is not required.

https://html.spec.whatwg.org/multipage/forms.html#submit-dialog

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@dpogue
Copy link
Author

dpogue commented Sep 18, 2015

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@Narretz
Copy link
Contributor

Narretz commented Sep 19, 2015

Shocking support for that element: http://caniuse.com/#feat=dialog
But I don't think it'll hurt, as someone who uses method="dialog" will know what they're doing. There's still some work to do for this though:

  • Add a test for this
  • Add a line to the docs that says submit will not be blocked when method is set to dialog.

@@ -485,7 +485,7 @@ var formDirectiveFactory = function(isNgForm) {
var controller = ctrls[0];

// if `action` attr is not present on the form, prevent the default action (submission)
if (!('action' in attr)) {
if (!('action' in attr) && attr['method'] !== 'dialog') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the action attr is set and method is set to dialog?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec, if method is dialog then it closes the dialog and stops further processing. The action attribute should be ignored by the browser in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is: if the action attribute is set and the method is set to dialog, your code change would not prevent the submit. Isn't !('action' in attr) || attr['method'] !== 'dialog' what we want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I misunderstood the purpose. I though it should block submit when the method is dialog, doh. Having the test really helps understanding what a change is about.

When a form's method is set to "dialog" it does not post to a server but
instead closes the nearest parent <dialog> element. An action is not required.
@dpogue
Copy link
Author

dpogue commented Sep 21, 2015

I've added a test and updated the comments. I'm not sure that blocking submit when method="dialog" with an action is what we want? It should be up to the browser to handle that properly.

@Narretz
Copy link
Contributor

Narretz commented Sep 21, 2015

Thanks for the test. Now that method="dialog" does not block submit anymore, I think we'd still want to have it call $commitViewValue and $setSubmitted on the form, right? Previously, it would set these only if the form wasn't sent to the server. Now the form isn't sent to the server, so I assume we still want that.

@Narretz Narretz self-assigned this Aug 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants