-1

I have a form with validation in the fields. I want to remove the validation on a specific condition.

I already tried clearValidators(), setErrors(null), setValidators(null), and updateValueAndValidity(), but none of these worked.

Roan
  • 63
  • 2
  • 7

1 Answers1

1

setValidators(null), must be work. It's posible you need call to updateValueAndValidity() in a setTimeout to remove the errors. If I supouse your formGroup is called form and has a formControl called myControl

this.form.get("myControl").setValidators(null)
setTimeout(()=>{
    this.form.get("myControl").updateValueAndValidity()
})

NOTE: If you disabled the control, the form don't take account the validators

this.form.get("myControl").disable()
Eliseo
  • 50,109
  • 4
  • 29
  • 67