@@ -12,7 +12,7 @@ import {StringMapWrapper} from '../facade/collection';
12
12
import { isBlank , isPresent , isPromise , isString } from '../facade/lang' ;
13
13
import { PromiseWrapper } from '../facade/promise' ;
14
14
import { AsyncValidatorFn , ValidatorFn } from './directives/validators' ;
15
- import * as modelModule from './model' ;
15
+ import { AbstractControl } from './model' ;
16
16
17
17
/**
18
18
* Providers for validators to be used for {@link Control}s in a form.
@@ -57,7 +57,7 @@ export class Validators {
57
57
/**
58
58
* Validator that requires controls to have a non-empty value.
59
59
*/
60
- static required ( control : modelModule . AbstractControl ) : { [ key : string ] : boolean } {
60
+ static required ( control : AbstractControl ) : { [ key : string ] : boolean } {
61
61
return isBlank ( control . value ) || ( isString ( control . value ) && control . value == '' ) ?
62
62
{ 'required' : true } :
63
63
null ;
@@ -67,7 +67,7 @@ export class Validators {
67
67
* Validator that requires controls to have a value of a minimum length.
68
68
*/
69
69
static minLength ( minLength : number ) : ValidatorFn {
70
- return ( control : modelModule . AbstractControl ) : { [ key : string ] : any } => {
70
+ return ( control : AbstractControl ) : { [ key : string ] : any } => {
71
71
if ( isPresent ( Validators . required ( control ) ) ) return null ;
72
72
var v : string = control . value ;
73
73
return v . length < minLength ?
@@ -80,7 +80,7 @@ export class Validators {
80
80
* Validator that requires controls to have a value of a maximum length.
81
81
*/
82
82
static maxLength ( maxLength : number ) : ValidatorFn {
83
- return ( control : modelModule . AbstractControl ) : { [ key : string ] : any } => {
83
+ return ( control : AbstractControl ) : { [ key : string ] : any } => {
84
84
if ( isPresent ( Validators . required ( control ) ) ) return null ;
85
85
var v : string = control . value ;
86
86
return v . length > maxLength ?
@@ -93,7 +93,7 @@ export class Validators {
93
93
* Validator that requires a control to match a regex to its value.
94
94
*/
95
95
static pattern ( pattern : string ) : ValidatorFn {
96
- return ( control : modelModule . AbstractControl ) : { [ key : string ] : any } => {
96
+ return ( control : AbstractControl ) : { [ key : string ] : any } => {
97
97
if ( isPresent ( Validators . required ( control ) ) ) return null ;
98
98
let regex = new RegExp ( `^${ pattern } $` ) ;
99
99
let v : string = control . value ;
@@ -105,7 +105,7 @@ export class Validators {
105
105
/**
106
106
* No-op validator.
107
107
*/
108
- static nullValidator ( c : modelModule . AbstractControl ) : { [ key : string ] : boolean } { return null ; }
108
+ static nullValidator ( c : AbstractControl ) : { [ key : string ] : boolean } { return null ; }
109
109
110
110
/**
111
111
* Compose multiple validators into a single function that returns the union
@@ -116,7 +116,7 @@ export class Validators {
116
116
var presentValidators = validators . filter ( isPresent ) ;
117
117
if ( presentValidators . length == 0 ) return null ;
118
118
119
- return function ( control : modelModule . AbstractControl ) {
119
+ return function ( control : AbstractControl ) {
120
120
return _mergeErrors ( _executeValidators ( control , presentValidators ) ) ;
121
121
} ;
122
122
}
@@ -126,7 +126,7 @@ export class Validators {
126
126
var presentValidators = validators . filter ( isPresent ) ;
127
127
if ( presentValidators . length == 0 ) return null ;
128
128
129
- return function ( control : modelModule . AbstractControl ) {
129
+ return function ( control : AbstractControl ) {
130
130
let promises = _executeAsyncValidators ( control , presentValidators ) . map ( _convertToPromise ) ;
131
131
return PromiseWrapper . all ( promises ) . then ( _mergeErrors ) ;
132
132
} ;
@@ -137,13 +137,11 @@ function _convertToPromise(obj: any): Promise<any> {
137
137
return isPromise ( obj ) ? obj : ObservableWrapper . toPromise ( obj ) ;
138
138
}
139
139
140
- function _executeValidators (
141
- control : modelModule . AbstractControl , validators : ValidatorFn [ ] ) : any [ ] {
140
+ function _executeValidators ( control : AbstractControl , validators : ValidatorFn [ ] ) : any [ ] {
142
141
return validators . map ( v => v ( control ) ) ;
143
142
}
144
143
145
- function _executeAsyncValidators (
146
- control : modelModule . AbstractControl , validators : AsyncValidatorFn [ ] ) : any [ ] {
144
+ function _executeAsyncValidators ( control : AbstractControl , validators : AsyncValidatorFn [ ] ) : any [ ] {
147
145
return validators . map ( v => v ( control ) ) ;
148
146
}
149
147
0 commit comments