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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ function FormController(element, attrs, $scope, $animate, $interpolate) {
* to handle the form submission in an application-specific way.
*
* For this reason, Angular prevents the default action (form submission to the server) unless the
* `<form>` element has an `action` attribute specified.
* `<form>` element has a `method` attribute with the value `"dialog"` or has an `action` attribute
* specified.
*
* You can use one of the following two ways to specify what javascript method should be called when
* a form is submitted:
Expand Down Expand Up @@ -485,7 +486,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.

// we can't use jq events because if a form is destroyed during submission the default
// action is not prevented. see #1238
//
Expand Down
14 changes: 14 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,20 @@ describe('form', function() {
browserTrigger(doc, 'submit');
expect(callback).toHaveBeenCalledOnce();
});


it('should NOT prevent form submission if method attribute id "dialog"', function() {
var callback = jasmine.createSpy('submit').andCallFake(function(event) {
expect(event.isDefaultPrevented()).toBe(false);
event.preventDefault();
});

doc = $compile('<form method="dialog"></form>')(scope);
doc.on('submit', callback);

browserTrigger(doc, 'submit');
expect(callback).toHaveBeenCalledOnce();
});
});


Expand Down