mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-05 21:54:42 +00:00
feat(directive): ng:focus, ng:blur
Added directives for focus and blur events. Closes #1277
This commit is contained in:
parent
1a8d83d660
commit
2bb27d4998
2 changed files with 49 additions and 1 deletions
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
var ngEventDirectives = {};
|
var ngEventDirectives = {};
|
||||||
forEach(
|
forEach(
|
||||||
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit'.split(' '),
|
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit focus blur'.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) {
|
||||||
|
|
@ -264,3 +264,33 @@ forEach(
|
||||||
</doc:scenario>
|
</doc:scenario>
|
||||||
</doc:example>
|
</doc:example>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngdoc directive
|
||||||
|
* @name ng.directive:ngFocus
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Specify custom behavior on focus event.
|
||||||
|
*
|
||||||
|
* @element window, input, select, textarea, a
|
||||||
|
* @param {expression} ngFocus {@link guide/expression Expression} to evaluate upon
|
||||||
|
* focus. (Event object is available as `$event`)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* See {@link ng.directive:ngClick ngClick}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngdoc directive
|
||||||
|
* @name ng.directive:ngBlur
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Specify custom behavior on blur event.
|
||||||
|
*
|
||||||
|
* @element window, input, select, textarea, a
|
||||||
|
* @param {expression} ngBlur {@link guide/expression Expression} to evaluate upon
|
||||||
|
* blur. (Event object is available as `$event`)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* See {@link ng.directive:ngClick ngClick}
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -34,5 +34,23 @@ describe('ngKeyup and ngKeydown directives', function() {
|
||||||
expect($rootScope.touched).toEqual(true);
|
expect($rootScope.touched).toEqual(true);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should get called on focus', inject(function($rootScope, $compile) {
|
||||||
|
element = $compile('<input ng-focus="touched = true">')($rootScope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect($rootScope.touched).toBeFalsy();
|
||||||
|
|
||||||
|
browserTrigger(element, 'focus');
|
||||||
|
expect($rootScope.touched).toEqual(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should get called on blur', inject(function($rootScope, $compile) {
|
||||||
|
element = $compile('<input ng-blur="touched = true">')($rootScope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect($rootScope.touched).toBeFalsy();
|
||||||
|
|
||||||
|
browserTrigger(element, 'blur');
|
||||||
|
expect($rootScope.touched).toEqual(true);
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue