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

Commit 86c7d12

Browse files
Artem TyurinIgorMinar
Artem Tyurin
authored andcommitted
fix(form): fix submit prevention
Do not prevent submit when action attribute equals to an empty string. Closes #3370 Closes #3776
1 parent 8da08a1 commit 86c7d12

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/ng/directive/form.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ var formDirectiveFactory = function(isNgForm) {
454454

455455
return {
456456
pre: function ngFormPreLink(scope, formElement, attr, controller) {
457-
if (!attr.action) {
457+
// if `action` attr is not present on the form, prevent the default action (submission)
458+
if (!('action' in attr)) {
458459
// we can't use jq events because if a form is destroyed during submission the default
459460
// action is not prevented. see #1238
460461
//

test/ng/directive/ngEventDirsSpec.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ describe('event directives', function() {
1212
describe('ngSubmit', function() {
1313

1414
it('should get called on form submit', inject(function($rootScope, $compile) {
15-
element = $compile('<form action="" ng-submit="submitted = true">' +
15+
element = $compile('<form action="/foo" ng-submit="submitted = true">' +
1616
'<input type="submit"/>' +
1717
'</form>')($rootScope);
1818
$rootScope.$digest();
19+
20+
// prevent submit within the test harness
21+
element.on('submit', function(e) { e.preventDefault(); });
22+
1923
expect($rootScope.submitted).not.toBeDefined();
2024

2125
browserTrigger(element.children()[0]);
@@ -29,10 +33,14 @@ describe('event directives', function() {
2933
}
3034
};
3135

32-
element = $compile('<form action="" ng-submit="formSubmission($event)">' +
36+
element = $compile('<form action="/foo" ng-submit="formSubmission($event)">' +
3337
'<input type="submit"/>' +
3438
'</form>')($rootScope);
3539
$rootScope.$digest();
40+
41+
// prevent submit within the test harness
42+
element.on('submit', function(e) { e.preventDefault(); });
43+
3644
expect($rootScope.formSubmitted).not.toBeDefined();
3745

3846
browserTrigger(element.children()[0]);

0 commit comments

Comments
 (0)