@@ -2,13 +2,12 @@ import angular from 'angular-fix';
2
2
export default formlyCustomValidation ;
3
3
4
4
// @ngInject
5
- function formlyCustomValidation ( formlyConfig , formlyUtil , $q , formlyWarn ) {
5
+ function formlyCustomValidation ( formlyUtil ) {
6
6
return {
7
7
restrict : 'A' ,
8
8
require : 'ngModel' ,
9
9
link : function formlyCustomValidationLink ( scope , el , attrs , ctrl ) {
10
10
const opts = scope . options ;
11
- const warnedValidators = [ ] ;
12
11
opts . validation . messages = opts . validation . messages || { } ;
13
12
angular . forEach ( opts . validation . messages , ( message , key ) => {
14
13
opts . validation . messages [ key ] = ( ) => {
@@ -41,45 +40,18 @@ function formlyCustomValidation(formlyConfig, formlyUtil, $q, formlyWarn) {
41
40
}
42
41
43
42
function setupWithValidators ( validator , name , isAsync ) {
44
- const isPossiblyAsync = ! angular . isString ( validator ) ;
45
- let validatorCollection = ( isPossiblyAsync || isAsync ) ? '$asyncValidators' : '$validators' ;
46
-
47
- // UPDATE IN 7.0.0
48
- // this is temporary until we can have a breaking change. Allow people to get the wins of the explicitAsync api
49
- if ( formlyConfig . extras . explicitAsync && ! isAsync ) {
50
- validatorCollection = '$validators' ;
51
- }
43
+ const validatorCollection = isAsync ? '$asyncValidators' : '$validators' ;
52
44
53
45
ctrl [ validatorCollection ] [ name ] = function evalValidity ( modelValue , viewValue ) {
54
- const value = formlyUtil . formlyEval ( scope , validator , modelValue , viewValue ) ;
55
- // UPDATE IN 7.0.0
56
- // In the next breaking change, this code should simply return the value
57
- if ( isAsync ) {
58
- return value ;
59
- } else if ( isPossiblyAsync && ! formlyConfig . extras . explicitAsync ) {
60
- if ( isPromiseLike ( value ) ) {
61
- logAsyncValidatorsDeprecationNotice ( validator , opts ) ;
62
- return value ;
63
- } else {
64
- return value ? $q . when ( value ) : $q . reject ( value ) ;
65
- }
66
- } else {
67
- return value ;
68
- }
46
+ return formlyUtil . formlyEval ( scope , validator , modelValue , viewValue ) ;
69
47
} ;
70
48
}
71
49
72
50
function setupWithParsers ( validator , name , isAsync ) {
73
51
let inFlightValidator ;
74
52
ctrl . $parsers . unshift ( function evalValidityOfParser ( viewValue ) {
75
53
const isValid = formlyUtil . formlyEval ( scope , validator , ctrl . $modelValue , viewValue ) ;
76
- // UPDATE IN 7.0.0
77
- // In the next breaking change, rather than checking for isPromiseLike, it should just check for isAsync.
78
-
79
- if ( isAsync || isPromiseLike ( isValid ) ) {
80
- if ( ! isAsync ) {
81
- logAsyncValidatorsDeprecationNotice ( validator , opts ) ;
82
- }
54
+ if ( isAsync ) {
83
55
ctrl . $pending = ctrl . $pending || { } ;
84
56
ctrl . $pending [ name ] = true ;
85
57
inFlightValidator = isValid ;
@@ -105,24 +77,6 @@ function formlyCustomValidation(formlyConfig, formlyUtil, $q, formlyWarn) {
105
77
return viewValue ;
106
78
} ) ;
107
79
}
108
-
109
- function logAsyncValidatorsDeprecationNotice ( validator , options ) {
110
- if ( warnedValidators . indexOf ( validator ) !== - 1 ) {
111
- // we've warned about this one before. No spam necessary...
112
- return ;
113
- }
114
- warnedValidators . push ( validator ) ;
115
- formlyWarn (
116
- 'validators-returning-promises-should-use-asyncvalidators' ,
117
- 'Validators returning promises should use asyncValidators instead of validators.' ,
118
- options
119
- ) ;
120
- }
121
80
}
122
81
} ;
123
-
124
-
125
- function isPromiseLike ( obj ) {
126
- return obj && angular . isFunction ( obj . then ) ;
127
- }
128
82
}
0 commit comments