@@ -5,18 +5,26 @@ angular.module('angularBootstrapMaterial')
55 label : '@'
66 } ,
77 transclude : true ,
8- require : '?^abmFormGroup' ,
8+ require : [ '?^abmFormGroup' ] ,
99 templateUrl : 'templates/checkbox.html' ,
10- link : function ( scope , element , attrs , ctrl , transclude ) {
11- transclude ( function ( clone , scope ) {
12- element . find ( 'abm-transclude-slot-checkbox' ) . replaceWith ( clone ) ;
10+ link : function ( $scope , $element , attrs , ctrls , transclude ) {
11+ var input ;
12+ var formGroup = ctrls [ 0 ] ;
13+ transclude ( function ( clone , $scope ) {
14+ $element . find ( 'abm-transclude-slot-checkbox' ) . replaceWith ( clone ) ;
1315 } , null ) ;
14- if ( ctrl ) {
15- var $input = element . find ( 'input' ) ;
16- element . find ( 'label' ) . on ( 'mouseenter mouseleave' , function ( event ) {
16+ if ( formGroup ) {
17+ var $input = $element . find ( 'input' ) ;
18+ input = $input . controller ( 'ngModel' ) ;
19+ $element . find ( 'label' ) . on ( 'mouseenter mouseleave' , function ( event ) {
1720 if ( $input . prop ( 'disabled' ) ) return ;
18- ctrl . toggleFocus ( event . type == 'mouseover' ) ;
21+ formGroup . toggleFocus ( event . type == 'mouseover' ) ;
1922 } ) ;
23+ if ( input ) {
24+ $scope . $watch ( function ( ) {
25+ return input . $invalid ;
26+ } , formGroup . toggleError ) ;
27+ }
2028 }
2129 }
2230 }
0 commit comments