Reputation: 91
In my ReactiveForm form, I add required validator to one formControl by condition.
if(condition) setRequired();
setRequired() { this.form.get(['company','id']).addValidators(Validators.required);}
but form.valid is true, even the field is empty.
Do I need to add something else?
Thanks.
Upvotes: 1
Views: 1126
Reputation: 2992
After remove/add validator to your form element, you have to invoke function with updateValueAndValidity
to update the state.
Like: this.form.updateValueAndValidity()
;
Or: this.form.get(['company','id']).updateValueAndValidity()
;
Upvotes: 1