diff --git a/src/directives.js b/src/directives.js index ea09fc06fcf1..54469ea77f3c 100644 --- a/src/directives.js +++ b/src/directives.js @@ -524,9 +524,8 @@ angularDirective("ng:click", function(expression, element){ angularDirective("ng:submit", function(expression, element) { return function(element) { var self = this; - element.bind('submit', function(event) { + element.bind('submit', function() { self.$apply(expression); - event.preventDefault(); }); }; }); diff --git a/src/widget/form.js b/src/widget/form.js index 51864cf0037a..7605183261dc 100644 --- a/src/widget/form.js +++ b/src/widget/form.js @@ -61,8 +61,8 @@ angularWidget('form', function(form){ parentForm = $formFactory.forElement(formElement), form = $formFactory(parentForm); formElement.data('$form', form); - formElement.bind('submit', function(event){ - event.preventDefault(); + formElement.bind('submit', function(event) { + if (!formElement.attr('action')) event.preventDefault(); }); if (name) { this[name] = form; diff --git a/test/widget/formSpec.js b/test/widget/formSpec.js index 7a92dbf43443..f2e90d9ebfca 100644 --- a/test/widget/formSpec.js +++ b/test/widget/formSpec.js @@ -29,6 +29,22 @@ describe('form', function() { })); + it('should not prevent form submission if action attribute present', + inject(function($compile, $rootScope) { + var callback = jasmine.createSpy('submit').andCallFake(function(event) { + expect(event.isDefaultPrevented()).toBe(false); + event.preventDefault(); + }); + + doc = angular.element('
'); + $compile(doc)($rootScope); + doc.bind('submit', callback); + + browserTrigger(doc, 'submit'); + expect(callback).toHaveBeenCalledOnce(); + })); + + it('should publish form to scope', inject(function($rootScope, $compile) { doc = angular.element('
'); $compile(doc)($rootScope);