mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
fix(ngSubmit): expose $event to ngSubmit callback
This commit is contained in:
parent
2c0753225a
commit
b0d5f062e3
3 changed files with 67 additions and 8 deletions
|
|
@ -87,7 +87,6 @@ function publishExternalAPI(angular){
|
|||
ngPluralize: ngPluralizeDirective,
|
||||
ngRepeat: ngRepeatDirective,
|
||||
ngShow: ngShowDirective,
|
||||
ngSubmit: ngSubmitDirective,
|
||||
ngStyle: ngStyleDirective,
|
||||
ngSwitch: ngSwitchDirective,
|
||||
ngSwitchWhen: ngSwitchWhenDirective,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
var ngEventDirectives = {};
|
||||
forEach(
|
||||
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave'.split(' '),
|
||||
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave submit'.split(' '),
|
||||
function(name) {
|
||||
var directiveName = directiveNormalize('ng-' + name);
|
||||
ngEventDirectives[directiveName] = ['$parse', function($parse) {
|
||||
|
|
@ -164,6 +164,54 @@ forEach(
|
|||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc directive
|
||||
* @name ng.directive:ngKeydown
|
||||
*
|
||||
* @description
|
||||
* Specify custom behavior on keydown event.
|
||||
*
|
||||
* @element ANY
|
||||
* @param {expression} ngKeydown {@link guide/expression Expression} to evaluate upon
|
||||
* keydown. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
|
||||
*
|
||||
* @example
|
||||
* See {@link ng.directive:ngClick ngClick}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc directive
|
||||
* @name ng.directive:ngKeyup
|
||||
*
|
||||
* @description
|
||||
* Specify custom behavior on keyup event.
|
||||
*
|
||||
* @element ANY
|
||||
* @param {expression} ngKeyup {@link guide/expression Expression} to evaluate upon
|
||||
* keyup. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
|
||||
*
|
||||
* @example
|
||||
* See {@link ng.directive:ngClick ngClick}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc directive
|
||||
* @name ng.directive:ngKeypress
|
||||
*
|
||||
* @description
|
||||
* Specify custom behavior on keypress event.
|
||||
*
|
||||
* @element ANY
|
||||
* @param {expression} ngKeypress {@link guide/expression Expression} to evaluate upon
|
||||
* keypress. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
|
||||
*
|
||||
* @example
|
||||
* See {@link ng.directive:ngClick ngClick}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc directive
|
||||
* @name ng.directive:ngSubmit
|
||||
|
|
@ -176,7 +224,7 @@ forEach(
|
|||
* attribute**.
|
||||
*
|
||||
* @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
|
||||
<doc:example>
|
||||
|
|
@ -216,8 +264,3 @@ forEach(
|
|||
</doc:scenario>
|
||||
</doc:example>
|
||||
*/
|
||||
var ngSubmitDirective = ngDirective(function(scope, element, attrs) {
|
||||
element.bind('submit', function() {
|
||||
scope.$apply(attrs.ngSubmit);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,5 +21,22 @@ describe('event directives', function() {
|
|||
browserTrigger(element.children()[0]);
|
||||
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