Multiple validators in the form

Asked

Viewed 39 times

0

I have the code seguints

inserir a descrição da imagem aqui

With the version of angular.json so:

"@angular/cli": "~6.0.0" 

When trying to use a more current version it looks like this: inserir a descrição da imagem aqui

With the angular cll so:

"@angular/cli": "1.2.7",

I wish in this latest version, I could put multiple Validators.

1 answer

1

Just enter "," and add new validators to the array. See the example:

password: new FormControl('', [Validatots.required, Validators.minLength(5), Validators.maxLength(10)]),

And so it goes..

Edit Using updateOn

new FormControl(null, {validators: Validators.compose([Validators.required, Validators.min(2500)]), updateOn: "blur"}),
  • And updateOn, would also enter the array?

  • That! in the update action also however you need to pass the value to be validated as the first argument of FormControl. I suggest you create a form-only method that accepts the default values of the fields as argument. In documentation has several well-chewed examples of how to validate the fields.

  • How it would look in the ['updateOn' array: 'Blur'] in the array?

  • @adventistaam updated the response with an example of using multiple validators and updateOn

Browser other questions tagged

You are not signed in. Login or sign up in order to post.