sad-indigoS
Refine15mo ago
23 replies
sad-indigo

hook form mui autocomplete

I am trying to report error if the value is not in the options to the autocomplete .

<FormControl sx={{ padding: 0 }}>
<Controller
control={control}
name={fieldName}
rules={{
required: t("errors.required.field", { field: fieldName }),
validate: (value) => {
console.log(value, options);
if (!options.some((option) => option.id === value.id)) {
return t("errors.invalid.option", { field: fieldName });
}
return true;
},
}}
Was this page helpful?