0

Suppose I set one custom validation to true on particular condition like this

if(condition){
this.form.contains['field'].setErrors({myValidation : true});
}

Then after some time I need to reset that particular validation (Not entire control validation) to false like

this.form.contains['field'].setErrors({myValidation : false});

It is not working. Here the only option is to set

this.form.contains['field'].setErrors(null);

But this sets all validation of the particular control to false.

How to set the particular validation of the control in the form to false?

Suresh Kumar
  • 172
  • 3
  • 12
  • 2
    Possible duplicate of [Angular 2 Forms Manually Mark invalid](https://stackoverflow.com/questions/43553544/angular-2-forms-manually-mark-invalid) – Huske Nov 30 '17 at 08:38
  • Did you try : `this.form.contains['field'].setErrors({myValidation : null});` – nightElf91 Nov 30 '17 at 09:38
  • It is not that duplicate. There they are suggesting to set all validations to null. But I'm asking how to set particular validation to null. @Husein – Suresh Kumar Nov 30 '17 at 10:20
  • 1
    Yes. Tried. It also makes the validation like True setting only. When we are entering some validation name inside .setErrors() it makes the validation 'true' without considering the option what we are giving. @Nishad – Suresh Kumar Nov 30 '17 at 10:22

0 Answers0