ng2-validation icon indicating copy to clipboard operation
ng2-validation copied to clipboard

Multiple Validators for the same input field.

Open phixMe opened this issue 8 years ago • 1 comments

I believe that it would be very useful to have a note about multiple validators for the same field.

I was able to accomplish this with:

this.myForm = fb.group({
  'cardNumber': new FormControl('', Validators.compose([Validators.required, CustomValidators.creditCard]))
});

phixMe avatar Nov 30 '16 19:11 phixMe

@phixMe I agree that this is missing in the documentation. In addition, the view is like this

<input type="text" formControlName="cardNumber" placeholder="cardNumber"/>
<p *ngIf="myForm.controls.cardNumber.errors?.creditCard || myForm.controls.cardNumber.errors?.required">invalid card</p>

Validation works but the ngIf doesn't

alvirtuoso avatar Feb 14 '17 19:02 alvirtuoso