Answer the question
In order to leave comments, you need to log in
How to check FormControl for validity from a function in angular?
There is this group:
this.OfferControl = this.fb.group({
leadLink: this.LeadControl.get('leadId').value,
area: ['', Validators.required],
regular: ['', Validators.required],
time: '',
details: this.fb.group({
fot: ['', Validators.required],
managerWage: ['', Validators.required],
tinkoffCommission: ['', Validators.required],
windowFond: ['', Validators.required],
material: ['', Validators.required],
profit: ['', Validators.required],
itog: ['', Validators.required],
itogMaterial: ['', Validators.required],
})
});
<form [formGroup]="OfferControl">
......
</form>
<button (click)="some()">Действия</button>
if (this.OfferControl.valid) {
...
}
Answer the question
In order to leave comments, you need to log in
valid and hasError are present not only for the whole group, but also for each field.
To highlight a field in red, you create a conditional class attribute based on valid for this field.
for example for area
[class.error]="!OfferControl.get('area').valid"
and then the element will get the error class when it becomes invalid.
And there the standard classes are hung up, open the form in devtools and see how it changes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question