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

Commit 6ca78f5

Browse files
committed
fix(ngForm): don't block submit when method=dialog
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.
1 parent 4dd10fd commit 6ca78f5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/ng/directive/form.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ function FormController(element, attrs, $scope, $animate, $interpolate) {
364364
* to handle the form submission in an application-specific way.
365365
*
366366
* For this reason, Angular prevents the default action (form submission to the server) unless the
367-
* `<form>` element has an `action` attribute specified.
367+
* `<form>` element has a `method` attribute with the value `"dialog"` or has an `action` attribute
368+
* specified.
368369
*
369370
* You can use one of the following two ways to specify what javascript method should be called when
370371
* a form is submitted:
@@ -485,7 +486,7 @@ var formDirectiveFactory = function(isNgForm) {
485486
var controller = ctrls[0];
486487

487488
// if `action` attr is not present on the form, prevent the default action (submission)
488-
if (!('action' in attr)) {
489+
if (!('action' in attr) && attr['method'] !== 'dialog') {
489490
// we can't use jq events because if a form is destroyed during submission the default
490491
// action is not prevented. see #1238
491492
//

test/ng/directive/formSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,20 @@ describe('form', function() {
483483
browserTrigger(doc, 'submit');
484484
expect(callback).toHaveBeenCalledOnce();
485485
});
486+
487+
488+
it('should NOT prevent form submission if method attribute id "dialog"', function() {
489+
var callback = jasmine.createSpy('submit').andCallFake(function(event) {
490+
expect(event.isDefaultPrevented()).toBe(false);
491+
event.preventDefault();
492+
});
493+
494+
doc = $compile('<form method="dialog"></form>')(scope);
495+
doc.on('submit', callback);
496+
497+
browserTrigger(doc, 'submit');
498+
expect(callback).toHaveBeenCalledOnce();
499+
});
486500
});
487501

488502

0 commit comments

Comments
 (0)