-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
ReferenceInput does not fetch current value #10634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is explained in the FAQ: https://marmelab.com/react-admin/FAQ.html#can-i-have-custom-identifiersprimary-keys-for-my-resources. |
@djhi , I understand that I can rename the Moreover, it appears that the React-Admin team anticipated such use cases, as the What I’m requesting is to extend this capability to the Would it be possible to reopen the issue? I have provided a code sandbox to demonstrate the issue: I've added 2 AutocompleteInput components, referencing authors1 and authors2 tables (see below) when I navigate to https://7wk6kf-8080.csb.app/#/comments/2, I see that the first drop-down box does not show a value, since it was not fetched <ReferenceInput
source="author.name"
reference="authors1"
page={1}
perPage={2}
queryOptions={{ refetchOnWindowFocus: false, retry: false }}
>
<AutocompleteInput
optionValue="name" //
/>
</ReferenceInput>
<ReferenceInput
source="author.name"
reference="authors2"
page={1}
perPage={50000000}
queryOptions={{ refetchOnWindowFocus: false, retry: false }}
>
<AutocompleteInput
optionValue="name" //
/>
</ReferenceInput>
authors1: [
{ id: 1, name: "Justina Hegmann" },
{ id: 2, name: "Ms. Brionna Smitham MD" },
{ id: 3, name: "Edmond Schulist" },
{ id: 4, name: "Danny Greenholt" },
{ id: 5, name: "Luciano Berge" },
{ id: 6, name: "Kiley Pouros" },
{ id: 7, name: "Annamarie Mayer" },
{ id: 8, name: "Breanna Gibson" },
{ id: 9, name: "Logan Schowalter" },
],
authors2: [
{ id: 1, name: "Justina Hegmann" },
{ id: 2, name: "Ms. Brionna Smitham MD" },
{ id: 3, name: "Edmond Schulist" },
{ id: 4, name: "Danny Greenholt" },
{ id: 5, name: "Luciano Berge" },
{ id: 6, name: "Kiley Pouros" },
{ id: 7, name: "Annamarie Mayer" },
{ id: 8, name: "Breanna Gibson" },
{ id: 9, name: "Logan Schowalter" },
], |
Hi @panfiva , The If you need to transform the data only for a specific call, you can pass a specific However I'll reopen the issue and mark it as a documentation enhancement, as we should probably explain that in the documentation. |
I am writing a AutoComplete input that stores values from
users
tablelogin
field. The code is as follows. Everything works just fine ifperPage
is large enough to include all records from users table. However, ifperPage
is small, then I am missing the current value in the drop-down box, and value appears to be emptyRoot-cause:
Reference input performs 2 queries from
useReferenceInputController
useGetList
to fetch possible valuesuseReference
to fetch current valuesThe issue with
useReference
query is that it expects value to includeid
. In my example above, I am usingusers.login
attribute instead ofusers.id
as optionValue; as the result, the only records that are received are the records returned byuseGetList
and, due to pagination settings, the current value may be missing from available choices and will not be displayed.Proposed fix
optionValue
attribute toReferenceInput
which defaults toid
optionValue === 'id'
, continue usinguseReference
as displayed belowoptionValue !== 'id'
, fetch current selection usinguseGetList
withfilter: { [optionValue]: currentValue }
Another issue is that sometimes values stored in current table's
owner
attribute are not found inusers.login
table (due to data retention issues). When that happens, the drop-down box will be empty.If a referenced value is still missing from
allChoices
andavailableChoices
, can we add{ [optionValue]: currentValue }
to these variables, so we can display invalid values as selected?The text was updated successfully, but these errors were encountered: