Is there a way to set a formGroup to invalid state manually?
I tried myForm.invalid = true;
and also myForm.status = 'INVALID'
But invalid
and status
are const
.
I dont want to mark a specific control as invalid. But the whole form.
$setDirty(); Sets the form to a dirty state. This method can be called to add the 'ng-dirty' class and set the form to a dirty state (ng-dirty class). This method will also propagate to parent forms.
In a reactive form, the source of truth is the component class. Instead of adding validators through attributes in the template, you add validator functions directly to the form control model in the component class. Angular then calls these functions whenever the value of the control changes.
Try this:
myForm.setErrors({ 'invalid': true });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With