afraid-scarlet
afraid-scarlet10mo ago

nested field name

in my edit page the name for an Autocomplete field is set to sudentInfo.lead.leadsQualification this since the api response is like this. All names for all fields including TextFields are like this. when I open the edit page. the value is correcly fethcing by textFields but not Autocomplete fields they are fetching only after another render occured in form
9 Replies
kapa.ai
kapa.ai10mo ago
Hi @alfazmuhammed. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, it seems like you're using the Autocomplete component from Material UI in your edit page. The Autocomplete component is used in conjunction with the Controller component from react-hook-form in the context of Refine. The issue you're facing might be related to how you're setting up the Autocomplete component. In the extracts, there's an example of how to set up the Autocomplete component with the Controller: ```jsx <Controller
control={control}
name="category"
rules={{ required: "This field is required" }}
// eslint-disable-next-line
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...categoryAutocompleteProps}
{...field}
onChange={(
, value) => {
field.onChange(value);
}}
getOptionLabel={(item) => {
return (
categoryAutocompleteProps?.options?.find(
(p) =>
p?.id?.toString() ===
item?.id?.toString(),
)?.title ?? ""
);
}}
isOptionEqualToValue={(option, value) =>
value === undefined ||
option?.id?.toString() ===
(value?.id ?? value)?.toString()
}
renderInput={(params) => (
<TextField
{...params}
label="Category"
margin="normal"
variant="outlined"
error={!!(errors as any)?.category?.id}
helperText={
(errors as any)?.category?.id?.message
}
required
/>
)}
/>
)}
/>
</Box>
</Edit>
);
}; `` In this example, the name prop of the Controller is set to "category". This should match the name of the field in your form data. If your API response has a nested structure like studentInfo.lead.leadsQualification, you should set the name prop to match this structure. If the issue persists, it might be related to how the defaultValue is set or how the onChange handler is implemented. Please ensure that these are set up correctly. If you need more detailed information, you can refer to the **Refine documentation** (<https://refine.dev/docs/api-reference/mui/components/basic-views/edit>) and **Refine blogs** (<https://refine.dev/blog>) for more examples and guides. ---------------------- Note: you can ask me a follow up question by @ mentioning me again` :speech_balloon: ----------------------
kapa.ai
kapa.ai10mo ago
<@763439201353596968> kapa.ai is still learning and improving, please let us know how it did by reacting below
afraid-scarlet
afraid-scarlet10mo ago
@kapa.ai the setup is correct and when I console logged the control from useForm I can see all the values from api are correcly then but in Autocomplete, the field prop from render in controller, whe ni console log that field.value shows null
kapa.ai
kapa.ai10mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the information provided in the extracts, it seems like you're using the Controller component from react-hook-form to control your Autocomplete component. The field.value you're referring to is the value passed to the render prop of the Controller. If field.value is null initially, it might be because the defaultValue prop of the Controller is set to null. In the provided extracts, there's an example where defaultValue is set to null as any:
<Controller
control={control}
name="category"
rules={{ required: "This field is required" }}
// eslint-disable-next-line
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...categoryAutocompleteProps}
{...field}
onChange={(_, value) => {
field.onChange(value);
}}
...
<Controller
control={control}
name="category"
rules={{ required: "This field is required" }}
// eslint-disable-next-line
defaultValue={null as any}
render={({ field }) => (
<Autocomplete
{...categoryAutocompleteProps}
{...field}
onChange={(_, value) => {
field.onChange(value);
}}
...
If you're expecting a different initial value, you should set defaultValue to that value. If the value is fetched asynchronously (e.g., from an API), you might need to handle this asynchronously, for example, by showing a loading state until the value is available. If the issue persists, it might be related to how the onChange handler is implemented. In the provided example, the onChange handler of the Autocomplete component calls field.onChange(value). This is how the field.value is updated when the user selects a different option in the Autocomplete component. If you need more detailed information, you can refer to the Refine documentation (https://refine.dev/docs/api-reference/mui/components/basic-views/edit) and Refine blogs (https://refine.dev/blog) for more examples and guides. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai10mo ago
<@763439201353596968> kapa.ai is still learning and improving, please let us know how it did by reacting below
afraid-scarlet
afraid-scarlet10mo ago
@kapa.ai I checked thorughly and there is mistake with my setup later I found that in the package.json, refine packages versions are given as "latest" so I changed them explicitely to versions "@refinedev/cli": "^2.1.0", "@refinedev/core": "^4.1.4", "@refinedev/inferencer": "^3.1.2", "@refinedev/mui": "^4.1.0", "@refinedev/react-hook-form": "^4.1.0", "@refinedev/react-router-v6": "^4.1.0", "@refinedev/simple-rest": "^4.1.0", thses are the versions I given but since some of thsese are seems to be not behaving correcly in app I think some versions are conflicting each other so can you tell me appropriate versin for aech to work correclty
kapa.ai
kapa.ai10mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the information provided in the extracts, there's a command in Refine's CLI that allows you to check the running versions of the installed Refine packages. You can run this command to see if there are any updates available for your packages:
npm run refine check-updates
npm run refine check-updates
This command will show you a table with the current, wanted, and latest versions of your installed Refine packages. If there are newer versions available, you can update your packages by running:
npm run refine update
npm run refine update
However, the extracts do not provide specific version numbers for each package that would work well together. It's generally recommended to use the latest versions of all packages to get the most recent features and bug fixes. If you're experiencing issues with certain packages, it might be helpful to look at the migration guide (https://refine.dev/docs/migration-guide/) provided in the Refine documentation. This guide provides information on how to migrate from older versions of Refine to newer ones, which might help resolve any conflicts you're experiencing. Remember to always test your application thoroughly after updating any packages to ensure everything still works as expected. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai10mo ago
<@763439201353596968> kapa.ai is still learning and improving, please let us know how it did by reacting below
useful-bronze
useful-bronze10mo ago
Hello @alfaz_muhammed, I had a hard time imagining the problem. If you provide a reproducible example, I would like to debug it.