1
1
/*!
2
2
* angular-ui-validate
3
3
* https://github.com/angular-ui/ui-validate
4
- * Version: 1.1.1 - 2015-07-20T03:33:55.729Z
4
+ * Version: 1.2.0 - 2015-09-29T04:34:17.056Z
5
5
* License: MIT
6
6
*/
7
7
14
14
* an arbitrary validation function requires creation of custom directives for interact with angular's validation mechanism.
15
15
* The ui-validate directive makes it easy to use any function(s) defined in scope as a validator function(s).
16
16
* A validator function will trigger validation on both model and input changes.
17
- *
17
+ *
18
18
* This utility bring 'ui-validate' directives to handle regular validations and 'ui-validate-async' for asynchronous validations.
19
19
*
20
20
* @example <input ui-validate=" 'myValidatorFunction($value)' ">
28
28
* If an object literal is passed a key denotes a validation error key while a value should be a validator function.
29
29
* In both cases validator function should take a value to validate as its argument and should return true/false indicating a validation result.
30
30
* It is possible for a validator function to return a promise, however promises are better handled by ui-validate-async.
31
- *
31
+ *
32
32
* @param ui-validate-async {string|object literal} If strings is passed it should be a scope's function to be used as a validator.
33
33
* If an object literal is passed a key denotes a validation error key while a value should be a validator function.
34
- * Async validator function should take a value to validate as its argument and should return a promise that resolves if valid and reject if not,
35
- * indicating a validation result.
34
+ * Async validator function should take a value to validate as its argument and should return a promise that resolves if valid and reject if not,
35
+ * indicating a validation result.
36
36
* ui-validate-async supports non asyncronous validators. They are wrapped into a promise. Although is recomented to use ui-validate instead, since
37
37
* all validations declared in ui-validate-async are registered un ngModel.$asyncValidators that runs after ngModel.$validators if and only if
38
38
* all validators in ngModel.$validators reports as valid.
39
39
*/
40
40
angular . module ( 'ui.validate' , [ ] )
41
- . directive ( 'uiValidate' , [ '$$uiValidateApplyWatch' , function ( $$uiValidateApplyWatch ) {
41
+ . directive ( 'uiValidate' , [ '$$uiValidateApplyWatch' , '$$uiValidateApplyWatchCollection' , function ( $$uiValidateApplyWatch , $$uiValidateApplyWatchCollection ) {
42
42
43
43
return {
44
44
restrict : 'A' ,
@@ -83,12 +83,15 @@ angular.module('ui.validate',[])
83
83
84
84
// Support for ui-validate-watch
85
85
if ( attrs . uiValidateWatch ) {
86
- $$uiValidateApplyWatch ( scope , ctrl , scope . $eval ( attrs . uiValidateWatch ) ) ;
86
+ $$uiValidateApplyWatch ( scope , ctrl , scope . $eval ( attrs . uiValidateWatch ) , attrs . uiValidateWatchObjectEquality ) ;
87
+ }
88
+ if ( attrs . uiValidateWatchCollection ) {
89
+ $$uiValidateApplyWatchCollection ( scope , ctrl , scope . $eval ( attrs . uiValidateWatchCollection ) ) ;
87
90
}
88
91
}
89
92
} ;
90
93
} ] )
91
- . directive ( 'uiValidateAsync' , [ '$$uiValidateApplyWatch' , '$timeout' , '$q' , function ( $$uiValidateApplyWatch , $timeout , $q ) {
94
+ . directive ( 'uiValidateAsync' , [ '$$uiValidateApplyWatch' , '$$uiValidateApplyWatchCollection' , '$ timeout', '$q' , function ( $$uiValidateApplyWatch , $$uiValidateApplyWatchCollection , $timeout , $q ) {
92
95
93
96
return {
94
97
restrict : 'A' ,
@@ -132,45 +135,75 @@ angular.module('ui.validate',[])
132
135
133
136
// Support for ui-validate-watch
134
137
if ( attrs . uiValidateWatch ) {
135
- $$uiValidateApplyWatch ( scope , ctrl , scope . $eval ( attrs . uiValidateWatch ) ) ;
138
+ $$uiValidateApplyWatch ( scope , ctrl , scope . $eval ( attrs . uiValidateWatch ) , attrs . uiValidateWatchObjectEquality ) ;
139
+ }
140
+ if ( attrs . uiValidateWatchCollection ) {
141
+ $$uiValidateApplyWatchCollection ( scope , ctrl , scope . $eval ( attrs . uiValidateWatchCollection ) ) ;
136
142
}
137
143
}
138
144
} ;
139
145
} ] )
140
- . service ( '$$uiValidateApplyWatch' , function ( ) {
141
- return function ( scope , ctrl , watch ) {
142
-
143
- //string - update all validators on expression change
144
- if ( angular . isString ( watch ) ) {
145
- scope . $watch ( watch , function ( ) {
146
+ . service ( '$$uiValidateApplyWatch' , function ( ) {
147
+ return function ( scope , ctrl , watch , objectEquality ) {
148
+ var watchCallback = function ( ) {
146
149
ctrl . $validate ( ) ;
147
- } ) ;
148
- //array - update all validators on change of any expression
149
- } else if ( angular . isArray ( watch ) ) {
150
- angular . forEach ( watch , function ( expression ) {
151
- scope . $watch ( expression , function ( ) {
152
- ctrl . $validate ( ) ;
150
+ } ;
151
+
152
+ //string - update all validators on expression change
153
+ if ( angular . isString ( watch ) ) {
154
+ scope . $watch ( watch , watchCallback , objectEquality ) ;
155
+ //array - update all validators on change of any expression
156
+ } else if ( angular . isArray ( watch ) ) {
157
+ angular . forEach ( watch , function ( expression ) {
158
+ scope . $watch ( expression , watchCallback , objectEquality ) ;
153
159
} ) ;
154
- } ) ;
155
- //object - update appropriate validator
156
- } else if ( angular . isObject ( watch ) ) {
157
- angular . forEach ( watch , function ( expression /*, validatorKey*/ ) {
158
- //value is string - look after one expression
159
- if ( angular . isString ( expression ) ) {
160
- scope . $watch ( expression , function ( ) {
161
- ctrl . $validate ( ) ;
162
- } ) ;
163
- }
164
- //value is array - look after all expressions in array
165
- if ( angular . isArray ( expression ) ) {
166
- angular . forEach ( expression , function ( intExpression ) {
167
- scope . $watch ( intExpression , function ( ) {
168
- ctrl . $validate ( ) ;
160
+ //object - update appropriate validator
161
+ } else if ( angular . isObject ( watch ) ) {
162
+ angular . forEach ( watch , function ( expression /*, validatorKey*/ ) {
163
+ //value is string - look after one expression
164
+ if ( angular . isString ( expression ) ) {
165
+ scope . $watch ( expression , watchCallback , objectEquality ) ;
166
+ }
167
+ //value is array - look after all expressions in array
168
+ if ( angular . isArray ( expression ) ) {
169
+ angular . forEach ( expression , function ( intExpression ) {
170
+ scope . $watch ( intExpression , watchCallback , objectEquality ) ;
169
171
} ) ;
170
- } ) ;
171
- }
172
- } ) ;
173
- } } ;
174
- } ) ;
172
+ }
173
+ } ) ;
174
+ }
175
+ } ;
176
+ } )
177
+ . service ( '$$uiValidateApplyWatchCollection' , function ( ) {
178
+ return function ( scope , ctrl , watch ) {
179
+ var watchCallback = function ( ) {
180
+ ctrl . $validate ( ) ;
181
+ } ;
182
+
183
+ //string - update all validators on expression change
184
+ if ( angular . isString ( watch ) ) {
185
+ scope . $watchCollection ( watch , watchCallback ) ;
186
+ //array - update all validators on change of any expression
187
+ } else if ( angular . isArray ( watch ) ) {
188
+ angular . forEach ( watch , function ( expression ) {
189
+ scope . $watchCollection ( expression , watchCallback ) ;
190
+ } ) ;
191
+ //object - update appropriate validator
192
+ } else if ( angular . isObject ( watch ) ) {
193
+ angular . forEach ( watch , function ( expression /*, validatorKey*/ ) {
194
+ //value is string - look after one expression
195
+ if ( angular . isString ( expression ) ) {
196
+ scope . $watchCollection ( expression , watchCallback ) ;
197
+ }
198
+ //value is array - look after all expressions in array
199
+ if ( angular . isArray ( expression ) ) {
200
+ angular . forEach ( expression , function ( intExpression ) {
201
+ scope . $watchCollection ( intExpression , watchCallback ) ;
202
+ } ) ;
203
+ }
204
+ } ) ;
205
+ }
206
+ } ;
207
+ } ) ;
175
208
176
209
} ( ) ) ;
0 commit comments