mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-03 04:34:44 +00:00
feat(form): do not prevent submission if action attribute present
This commit is contained in:
parent
163e05ed36
commit
c9f2b1eec5
3 changed files with 19 additions and 4 deletions
|
|
@ -524,9 +524,8 @@ angularDirective("ng:click", function(expression, element){
|
||||||
angularDirective("ng:submit", function(expression, element) {
|
angularDirective("ng:submit", function(expression, element) {
|
||||||
return function(element) {
|
return function(element) {
|
||||||
var self = this;
|
var self = this;
|
||||||
element.bind('submit', function(event) {
|
element.bind('submit', function() {
|
||||||
self.$apply(expression);
|
self.$apply(expression);
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ angularWidget('form', function(form){
|
||||||
parentForm = $formFactory.forElement(formElement),
|
parentForm = $formFactory.forElement(formElement),
|
||||||
form = $formFactory(parentForm);
|
form = $formFactory(parentForm);
|
||||||
formElement.data('$form', form);
|
formElement.data('$form', form);
|
||||||
formElement.bind('submit', function(event){
|
formElement.bind('submit', function(event) {
|
||||||
event.preventDefault();
|
if (!formElement.attr('action')) event.preventDefault();
|
||||||
});
|
});
|
||||||
if (name) {
|
if (name) {
|
||||||
this[name] = form;
|
this[name] = form;
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
it('should publish form to scope', inject(function($rootScope, $compile) {
|
||||||
doc = angular.element('<form name="myForm"></form>');
|
doc = angular.element('<form name="myForm"></form>');
|
||||||
$compile(doc)($rootScope);
|
$compile(doc)($rootScope);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue