How can I add multiple validators to a FormGroup.
A FormControl can accept an array of validators, however a FormGroup cannot. Is there a workaround aside from creating a single custom validator?
I am using rc4.
How can I add multiple validators to a FormGroup.
A FormControl can accept an array of validators, however a FormGroup cannot. Is there a workaround aside from creating a single custom validator?
I am using rc4.
Multiple validators can be combined through Validators.compose()
.
From the api reference:
compose(validators: ValidatorFn[]) : ValidatorFn
Compose multiple validators into a single function that returns the union of the individual error maps.
Actually, FormGroup did accept array of validators. Just that the interface not updated. Cast it to any will do. E.g.
<any>[Validators.required, Validators.minlength(2)]