Insert field on load for autocomplete component
I cant seem to find issue on the following code block, I can provide more of the edit.tsx if needed:
const { autocompleteProps, queryResult: coach_data } =
useAutocomplete<ICoaches>({
resource: "activeCoaches",
sorters: [
{
field: "coach_name",
order: "asc",
},
],
defaultValue: activeStudentsData?.coach_full_name,
});
<Controller
control={control}
name="coach_fullname"
rules={{ required: "This field is required" }}
// eslint-disable-next-line
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...autocompleteProps}
{...field}
onChange={(, value) => {
field.onChange(value);
}}
getOptionLabel={(item) => {
return (
autocompleteProps?.options?.find(
(p) =>
p?.coach_name?.toString() === item?.coach_name?.toString()
)?.coach_name ?? ""
);
}}
isOptionEqualToValue={(option, value) =>
value === undefined ||
option?.coach_name?.toString() ===
(value?.coach_name ?? value)?.toString()
}
renderInput={(params) => (
<TextField
{...params}
label="Koç İsmi"
margin="normal"
variant="outlined"
error={!!errors.coach_full_name}
helperText={errors.coach_full_name?.message}
required
/>
)}
/>
)}
/>
const { autocompleteProps, queryResult: coach_data } =
useAutocomplete<ICoaches>({
resource: "activeCoaches",
sorters: [
{
field: "coach_name",
order: "asc",
},
],
defaultValue: activeStudentsData?.coach_full_name,
});
<Controller
control={control}
name="coach_fullname"
rules={{ required: "This field is required" }}
// eslint-disable-next-line
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...autocompleteProps}
{...field}
onChange={(, value) => {
field.onChange(value);
}}
getOptionLabel={(item) => {
return (
autocompleteProps?.options?.find(
(p) =>
p?.coach_name?.toString() === item?.coach_name?.toString()
)?.coach_name ?? ""
);
}}
isOptionEqualToValue={(option, value) =>
value === undefined ||
option?.coach_name?.toString() ===
(value?.coach_name ?? value)?.toString()
}
renderInput={(params) => (
<TextField
{...params}
label="Koç İsmi"
margin="normal"
variant="outlined"
error={!!errors.coach_full_name}
helperText={errors.coach_full_name?.message}
required
/>
)}
/>
)}
/>
