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

Commit c9f2b1e

Browse files
vojtajinaIgorMinar
authored andcommitted
feat(form): do not prevent submission if action attribute present
1 parent 163e05e commit c9f2b1e

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/directives.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,8 @@ angularDirective("ng:click", function(expression, element){
524524
angularDirective("ng:submit", function(expression, element) {
525525
return function(element) {
526526
var self = this;
527-
element.bind('submit', function(event) {
527+
element.bind('submit', function() {
528528
self.$apply(expression);
529-
event.preventDefault();
530529
});
531530
};
532531
});

src/widget/form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ angularWidget('form', function(form){
6161
parentForm = $formFactory.forElement(formElement),
6262
form = $formFactory(parentForm);
6363
formElement.data('$form', form);
64-
formElement.bind('submit', function(event){
65-
event.preventDefault();
64+
formElement.bind('submit', function(event) {
65+
if (!formElement.attr('action')) event.preventDefault();
6666
});
6767
if (name) {
6868
this[name] = form;

test/widget/formSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ describe('form', function() {
2929
}));
3030

3131

32+
it('should not prevent form submission if action attribute present',
33+
inject(function($compile, $rootScope) {
34+
var callback = jasmine.createSpy('submit').andCallFake(function(event) {
35+
expect(event.isDefaultPrevented()).toBe(false);
36+
event.preventDefault();
37+
});
38+
39+
doc = angular.element('<form name="x" action="some.py" />');
40+
$compile(doc)($rootScope);
41+
doc.bind('submit', callback);
42+
43+
browserTrigger(doc, 'submit');
44+
expect(callback).toHaveBeenCalledOnce();
45+
}));
46+
47+
3248
it('should publish form to scope', inject(function($rootScope, $compile) {
3349
doc = angular.element('<form name="myForm"></form>');
3450
$compile(doc)($rootScope);

0 commit comments

Comments
 (0)