I am using angular 7 with material design components
I have requirement to add requireMatch validation to mat-autocomplete.
I have created custom validation with param but param value does change dynamically.
Below is my component code.
this.stepFormGroup = this.formBuilder.group({
AccessCode: ["", [Validators.required, this.requireMatch(this.accessCodeList)]]
});
////require-match validation for access-code
requireMatch = (accessCodes: string[]) => {
return (control: FormControl) => {
const selection: any = control.value;
console.log("accessCodes", accessCodes, "selection", selection);
if (accessCodes.indexOf(selection)===-1) {
return { requireMatch: true };
}
return null;
}
}
Issue i am facing that i am always getting empty(init) in accessCodes
inside requireMatch
.
Changes of this.accessCodeList
does not reflect to validator.
Meaning after changing this.accessCodeList
it doesn't get updated array in requireMatch
validator.
So anyone have any idea about how to pass dynamic param in custom-validator?
this.stepFormGroup.get('AccessCode').setValidators([Validators.required, this.requireMatch(this.accessCodeList)])
– Reflexthis.stepFormGroup.get('AccessCode').updateValueAndValidity()
after change the validator – Reflexthis.accessCodeList
changes. Still not getting updated list in validator – Sapphirathis.accessCodeList
in validator – SapphiraaccessCodes.indexOf(selection)<0
– Reflex