rxweb.io
rxweb.io copied to clipboard
I am not able to set the custom validator for formarray.
@ram54118 Please share the code snippet.
export class TestInfo{ @prop() id: string;
@required() @email({ message: 'Invalid email' }) email: string;
@required() type: string;
@prop() primary: boolean;
@prop() changeType: string;
@prop() verified: boolean;
@prop() verifiedDate: string;
@prop() allowEdit: string; @prop() allowDelete: string; @prop() markedForDeletion: string; }
export class TestInfoDetails { // I want to add custom validator(atleastOnePrimary below validator) for this formArray. @propArray(TestInfo) items: Array<TestInfo>; }
// Validator: public static atleastOnePrimary() { const validator: ValidatorFn = (formArray: FormArray) => { const primaryList = formArray.controls.filter( (group: FormGroup) => group.controls.primary.value === true && group.controls.markedForDeletion.value !== true );
return primaryList && primaryList.length === 1 ? null : { onePrimary: false };
};
return validator;
}