0

I've got a problem with my reactive forms - my repeatPassword doesn't refresh. If I write something in "password" label, then in "repeatPassword" and again in "password" the second one is not marked as invalid.

So I decided to do something like that:

if (this.form.get('password').value !== this.form.get('passwordRepeat').value) {
  this.form.get('passwordRepeat').setErrors({'invalid': true});
}

if (this.form.get('password').value === this.form.get('passwordRepeat').value &&
  !this.form.get('passwordRepeat').hasError) {
  this.form.get('passwordRepeat').setErrors({'invalid': null});
}

The code looks fine until I try to set invalid to null - reactive forms treat it like an error, so I can't submit and ngif shows an error.

The same error occurs when I'm trying to accept rules - unchecking checkbox doesn't mark it as invalid.

Is there any option that forces validators to run once again?

fool-dev
  • 7,671
  • 9
  • 40
  • 54
Chocho
  • 57
  • 6

1 Answers1

0

Have you tried setting this.form.get('passwordRepeat').setErrors(null); instead of this.form.get('passwordRepeat').setErrors({'invalid': null});?

Also this.form.get('passwordRepeat').setErrors({'invalid': false}); should work properly.

See this answer on SO that explains how to set validation errors in component.

FedeMITIC
  • 93
  • 1
  • 5