mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-10 07:44:43 +00:00
fix(ngSubmit): expose $event to ngSubmit callback
This commit is contained in:
parent
09a1e7af12
commit
3371fc254a
3 changed files with 19 additions and 8 deletions
|
|
@ -88,7 +88,6 @@ function publishExternalAPI(angular){
|
||||||
ngPluralize: ngPluralizeDirective,
|
ngPluralize: ngPluralizeDirective,
|
||||||
ngRepeat: ngRepeatDirective,
|
ngRepeat: ngRepeatDirective,
|
||||||
ngShow: ngShowDirective,
|
ngShow: ngShowDirective,
|
||||||
ngSubmit: ngSubmitDirective,
|
|
||||||
ngStyle: ngStyleDirective,
|
ngStyle: ngStyleDirective,
|
||||||
ngSwitch: ngSwitchDirective,
|
ngSwitch: ngSwitchDirective,
|
||||||
ngSwitchWhen: ngSwitchWhenDirective,
|
ngSwitchWhen: ngSwitchWhenDirective,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
var ngEventDirectives = {};
|
var ngEventDirectives = {};
|
||||||
forEach(
|
forEach(
|
||||||
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress'.split(' '),
|
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit'.split(' '),
|
||||||
function(name) {
|
function(name) {
|
||||||
var directiveName = directiveNormalize('ng-' + name);
|
var directiveName = directiveNormalize('ng-' + name);
|
||||||
ngEventDirectives[directiveName] = ['$parse', function($parse) {
|
ngEventDirectives[directiveName] = ['$parse', function($parse) {
|
||||||
|
|
@ -224,7 +224,7 @@ forEach(
|
||||||
* attribute**.
|
* attribute**.
|
||||||
*
|
*
|
||||||
* @element form
|
* @element form
|
||||||
* @param {expression} ngSubmit {@link guide/expression Expression} to eval.
|
* @param {expression} ngSubmit {@link guide/expression Expression} to eval. (Event object is available as `$event`)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
<doc:example>
|
<doc:example>
|
||||||
|
|
@ -264,8 +264,3 @@ forEach(
|
||||||
</doc:scenario>
|
</doc:scenario>
|
||||||
</doc:example>
|
</doc:example>
|
||||||
*/
|
*/
|
||||||
var ngSubmitDirective = ngDirective(function(scope, element, attrs) {
|
|
||||||
element.on('submit', function() {
|
|
||||||
scope.$apply(attrs.ngSubmit);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,22 @@ describe('event directives', function() {
|
||||||
browserTrigger(element.children()[0]);
|
browserTrigger(element.children()[0]);
|
||||||
expect($rootScope.submitted).toEqual(true);
|
expect($rootScope.submitted).toEqual(true);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should expose event on form submit', inject(function($rootScope, $compile) {
|
||||||
|
$rootScope.formSubmission = function(e) {
|
||||||
|
if (e) {
|
||||||
|
$rootScope.formSubmitted = 'foo';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
element = $compile('<form action="" ng-submit="formSubmission($event)">' +
|
||||||
|
'<input type="submit"/>' +
|
||||||
|
'</form>')($rootScope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect($rootScope.formSubmitted).not.toBeDefined();
|
||||||
|
|
||||||
|
browserTrigger(element.children()[0]);
|
||||||
|
expect($rootScope.formSubmitted).toEqual('foo');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue