How can I validate each FormGroup in a FormArray? Here I have the custom validator:
export class GridProcessorValidator {
static validateGroupItem(definition: ObjectDefinition) {
return function(control: AbstractControl): ValidatorFn {
return null;
};
}
}
And here is the form:
this.gridProcessorForm = this.fb.group({
propertiesSide: new FormControl(),
objectNamesSide: new FormControl(),
groupItems: this.fb.array([], validateGroupItem(this.myCollection)) // array of form groups that needs custom validation
});
How can I access the values of FormGroups within the custom validator definitionPropertiesMatched so I can check it then print it to the template for individual FormGroups that are invalid?
Template:
*ngFor="let item of gridProcessorForm.get('groupItems').controls; let i=index"
[formGroupName]="i"> ...
Then I have form field accessor:
{{item.get('propertyName').value}}
Is there a way I can get any errors for an item (FormGroup) in the iterator?
this.fb.array([], validateGroupItem(this.myCollection))tothis.fb.array([{'controlName' : ' '}], validateGroupItem(this.myCollection))