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

Commit

Permalink
feat(form): do not prevent submission if action attribute present
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina authored and IgorMinar committed Dec 6, 2011
1 parent 163e05e commit c9f2b1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
};
});
Expand Down
4 changes: 2 additions & 2 deletions src/widget/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/widget/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<form name="x" action="some.py" />');
$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('<form name="myForm"></form>');
$compile(doc)($rootScope);
Expand Down

0 comments on commit c9f2b1e

Please sign in to comment.