Is it possible to compare a form field's input to a List using custom validators? I am NOT trying to compare two Form Controls to each other.
I have been trying with this approach:
this.formGroupName = this.formBuilder.group({
category: ['', Validators.compose([Validators.required, this.checkCategoryInput(
this.formGroupName.get['category'].value, this.categoryList)])]
});
where in the checkCategoryInput()
method I will compare the value of the 'category' form control to a list of acceptable categories.
public checkCategoryInput(input: string, categoryList: any[]): {[key: string]: boolean} | null{
console.log(input);
console.log(categoryList);
return null;
}
However I am getting lost in the syntax and getting a few errors trying to do it with this approach. Does anyone have a better way to compare form control values to a list???