I'm building a form using Material UI and using react hook form for validation. It works perfectly using react hook form's Controller component except for Autocomplete. While it captures the Autocomplete data, the error handling doesn't work. I'm assuming it's because while the error object is passed down from the Controller => Autocomplete, it isn't passed down to the nested TextField component. It doesn't work if I do the error validation on the Autocomplete component instead either. Anyone has solved this? My component code is below
<Controller
name="categories"
control={control}
defaultValue=''
render={(props) =>
<Autocomplete
className='formInputs'
options={categories}
renderInput={params =>
<TextField
name='autoCompleteTextField'
{...params}
// value={props.field.value}
label="What do you do?"
variant="outlined"
rules={{
required: {
value: true,
message: "Please tell us what you're an expert on. It helps us prioritize your referrals"
}
}}
error={Boolean(props.fieldState.error)}
onChange={(e, data) => props.field.onChange(data)}
{...props}
/>
}
/>
}
/>