@@ -7,18 +7,26 @@ angular.module('angularBootstrapMaterial')
77 label : '@'
88 } ,
99 transclude : true ,
10- require : '?^abmFormGroup' ,
10+ require : [ '?^abmFormGroup' ] ,
1111 templateUrl : 'templates/checkbox.html' ,
12- link : function ( scope , element , attrs , ctrl , transclude ) {
13- transclude ( function ( clone , scope ) {
14- element . find ( 'abm-transclude-slot-checkbox' ) . replaceWith ( clone ) ;
12+ link : function ( $scope , $element , attrs , ctrls , transclude ) {
13+ var input ;
14+ var formGroup = ctrls [ 0 ] ;
15+ transclude ( function ( clone , $scope ) {
16+ $element . find ( 'abm-transclude-slot-checkbox' ) . replaceWith ( clone ) ;
1517 } , null ) ;
16- if ( ctrl ) {
17- var $input = element . find ( 'input' ) ;
18- element . find ( 'label' ) . on ( 'mouseenter mouseleave' , function ( event ) {
18+ if ( formGroup ) {
19+ var $input = $element . find ( 'input' ) ;
20+ input = $input . controller ( 'ngModel' ) ;
21+ $element . find ( 'label' ) . on ( 'mouseenter mouseleave' , function ( event ) {
1922 if ( $input . prop ( 'disabled' ) ) return ;
20- ctrl . toggleFocus ( event . type == 'mouseover' ) ;
23+ formGroup . toggleFocus ( event . type == 'mouseover' ) ;
2124 } ) ;
25+ if ( input ) {
26+ $scope . $watch ( function ( ) {
27+ return input . $invalid ;
28+ } , formGroup . toggleError ) ;
29+ }
2230 }
2331 }
2432 }
@@ -91,7 +99,7 @@ angular.module('angularBootstrapMaterial')
9199 /*templateUrl: 'templates/input.html',
92100 replace: true,*/
93101 scope : { } ,
94- require : [ " ngModel" , '^abmFormGroup' ] ,
102+ require : [ ' ngModel' , '^abmFormGroup' ] ,
95103 compile : function ( ) {
96104 return function ( $scope , $element , attrs , ctrls ) {
97105 var input = ctrls [ 0 ] ;
@@ -101,15 +109,17 @@ angular.module('angularBootstrapMaterial')
101109 if ( ! $element . attr ( 'id' ) ) // TBD checkif the condition is unnecessary
102110 $element . attr ( 'id' , 'form-control-' + $scope . $id ) ;
103111 formGroup . registerControl ( $scope ) ;
104- $element . on ( " input paste" , function ( e ) {
112+ $element . on ( ' input paste' , function ( e ) {
105113 if ( isChar ( e ) ) {
106114 formGroup . toggleEmpty ( true ) ;
107115 }
108- } ) . on ( " focus" , function ( ) {
116+ } ) . on ( ' focus' , function ( ) {
109117 formGroup . toggleFocus ( true ) ;
110118 } )
111- . on ( " blur" , function ( ) {
119+ . on ( ' blur' , function ( ) {
112120 formGroup . toggleFocus ( false ) ;
121+ if ( $element . val ( ) )
122+ formGroup . toggleEmpty ( false ) ;
113123 } ) ;
114124
115125 $scope . $watch ( function ( ) {
@@ -197,17 +207,23 @@ angular.module('angularBootstrapMaterial')
197207 transclude : true ,
198208 require : '?^abmFormGroup' ,
199209 templateUrl : 'templates/radio.html' ,
200- link : function ( scope , element , attrs , ctrl , transclude ) {
201- transclude ( function ( clone , scope ) {
210+ link : function ( $ scope, element , attrs , formGroup , transclude ) {
211+ transclude ( function ( clone , $ scope) {
202212 element . find ( 'abm-transclude-slot-radio' ) . replaceWith ( clone ) ;
203213 } , null ) ;
204214
205- if ( ctrl ) {
215+ if ( formGroup ) {
206216 var $input = element . find ( 'input' ) ;
217+ input = $input . controller ( 'ngModel' ) ;
207218 element . find ( 'label' ) . on ( 'mouseenter mouseleave' , function ( event ) {
208219 if ( $input . prop ( 'disabled' ) ) return ;
209- ctrl . toggleFocus ( event . type == 'mouseover' ) ;
220+ formGroup . toggleFocus ( event . type == 'mouseover' ) ;
210221 } ) ;
222+ if ( input ) {
223+ $scope . $watch ( function ( ) {
224+ return input . $invalid ;
225+ } , formGroup . toggleError ) ;
226+ }
211227 }
212228 }
213229 }
0 commit comments