This repository was archived by the owner on Apr 30, 2018. It is now read-only.
File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ export default ngModule => {
17
17
valueProp : c . string . optional
18
18
} )
19
19
} ,
20
+ defaultOptions : {
21
+ ngModelAttrs :{
22
+ required : {
23
+ attribute : '' ,
24
+ bound : ''
25
+ }
26
+ }
27
+ } ,
20
28
apiCheckInstance : c ,
21
29
controller : /* @ngInject */ function ( $scope ) {
22
30
const to = $scope . to ;
@@ -35,15 +43,42 @@ export default ngModule => {
35
43
} ) ;
36
44
}
37
45
46
+ function checkValidity ( expressionValue ) {
47
+ var valid = angular . isArray ( $scope . model [ opts . key ] ) &&
48
+ $scope . model [ opts . key ] . length > 0 &&
49
+ expressionValue ;
50
+
51
+ $scope . fc . $setValidity ( 'required' , valid ) ;
52
+ }
53
+
38
54
function setModel ( ) {
39
55
$scope . model [ opts . key ] = [ ] ;
40
56
angular . forEach ( $scope . multiCheckbox . checked , ( checkbox , index ) => {
41
57
if ( checkbox ) {
42
58
$scope . model [ opts . key ] . push ( to . options [ index ] [ to . valueProp || 'value' ] ) ;
43
59
}
44
60
} ) ;
61
+
62
+ // Must make sure we mark as touched because only the last checkbox due to a bug in angular.
63
+ $scope . fc . $setTouched ( ) ;
64
+ checkValidity ( true ) ;
65
+ }
66
+
67
+ if ( opts . expressionProperties && opts . expressionProperties . required ) {
68
+ $scope . $watch ( $scope . options . expressionProperties . required , function ( newValue ) {
69
+ checkValidity ( newValue ) ;
70
+ } ) ;
71
+ }
72
+
73
+ if ( $scope . to . required ) {
74
+ var unwatchFormControl = $scope . $watch ( 'fc' , function ( newValue ) {
75
+ if ( ! newValue ) { return ; }
76
+ checkValidity ( true ) ;
77
+ unwatchFormControl ;
78
+ } ) ;
45
79
}
46
80
}
47
81
} ) ;
48
82
}
83
+
49
84
} ;
You can’t perform that action at this time.
0 commit comments