diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 717d17a6e159..a89c0e46e4eb 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -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 // diff --git a/test/ng/directive/ngEventDirsSpec.js b/test/ng/directive/ngEventDirsSpec.js index 71e89343d289..d75398228e59 100644 --- a/test/ng/directive/ngEventDirsSpec.js +++ b/test/ng/directive/ngEventDirsSpec.js @@ -12,10 +12,14 @@ describe('event directives', function() { describe('ngSubmit', function() { it('should get called on form submit', inject(function($rootScope, $compile) { - element = $compile('
' + + element = $compile('' + '' + '
')($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]); @@ -29,10 +33,14 @@ describe('event directives', function() { } }; - element = $compile('
' + + element = $compile('' + '' + '
')($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]);