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

Commit

Permalink
fix(form): fix submit prevention
Browse files Browse the repository at this point in the history
Do not prevent submit when action
attribute equals to an empty string.

Closes #3370
Closes #3776
  • Loading branch information
Artem Tyurin authored and IgorMinar committed Oct 2, 2014
1 parent 8da08a1 commit 86c7d12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ var formDirectiveFactory = function(isNgForm) {

return {
pre: function ngFormPreLink(scope, formElement, attr, controller) {
if (!attr.action) {
// if `action` attr is not present on the form, prevent the default action (submission)
if (!('action' in attr)) {
// we can't use jq events because if a form is destroyed during submission the default
// action is not prevented. see #1238
//
Expand Down
12 changes: 10 additions & 2 deletions test/ng/directive/ngEventDirsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ describe('event directives', function() {
describe('ngSubmit', function() {

it('should get called on form submit', inject(function($rootScope, $compile) {
element = $compile('<form action="" ng-submit="submitted = true">' +
element = $compile('<form action="/foo" ng-submit="submitted = true">' +
'<input type="submit"/>' +
'</form>')($rootScope);
$rootScope.$digest();

// prevent submit within the test harness
element.on('submit', function(e) { e.preventDefault(); });

expect($rootScope.submitted).not.toBeDefined();

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

element = $compile('<form action="" ng-submit="formSubmission($event)">' +
element = $compile('<form action="/foo" ng-submit="formSubmission($event)">' +
'<input type="submit"/>' +
'</form>')($rootScope);
$rootScope.$digest();

// prevent submit within the test harness
element.on('submit', function(e) { e.preventDefault(); });

expect($rootScope.formSubmitted).not.toBeDefined();

browserTrigger(element.children()[0]);
Expand Down

0 comments on commit 86c7d12

Please sign in to comment.