Skip to content
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

ReferenceInput children not showing "name" optionText when prop is missing #8165

Closed
ZachSelindh opened this issue Sep 14, 2022 · 4 comments · Fixed by #8386
Closed

ReferenceInput children not showing "name" optionText when prop is missing #8165

ZachSelindh opened this issue Sep 14, 2022 · 4 comments · Fixed by #8386

Comments

@ZachSelindh
Copy link
Contributor

ZachSelindh commented Sep 14, 2022

What you were expecting:
To see a record's "name" value as optionText in an AutocompleteInput or SelectInput when they are a child of a ReferenceInput, and when "optionText" is not given as a prop ("name" is listed as the default optionText in the docs). Adding the optionText="name" prop fixes the issue.

What happened instead:
The record's ID is shown instead, as in #${id}. This bug also has implications for ReferenceInputs with inline Create functionality; the "Create" item is shown as "@@ra-create" instead of "Create".

Steps to reproduce:
Create a ReferenceInput / SelectInput combo (or AutocompleteInput) and do not pass the "optionText" prop.

Related code:
I would love to submit a codesandbox for this, but the RA codesandbox appears to be broken; forking it results in numerous errors and an "Initializing" screen that never loads. Not sure if this is an issue with codesanbox or the RA sandbox in particular.

Other information:

Environment

  • React-admin version: 4.3.2
  • Last version that did not exhibit the issue (if applicable): 4.2.6
  • React version: 17
  • Browser: Chrome
  • Stack trace (in case of a JS error):
@slax57
Copy link
Contributor

slax57 commented Sep 15, 2022

Thanks for this report.

Actually I think it's rather a documentation issue.
Indeed since #8011 , we now use the recordRepresentation as default when no optionText is provided. And this recordRepresentation defaults to the 'id' field.

But now I realize this is actually a BC for AutocompleteInput and SelectInput. Maybe we need to put back 'name' as default optionText for them...

Hence I'm marking this as a bug for now.

@slax57 slax57 added the bug label Sep 15, 2022
@fzaninotto
Copy link
Member

There is indeed a slight BC break: if you didn't use optionText and your record happened to have a name field, then it now shows the id. I'm willing to live with it as the fix is simple (add a recordRepresentation in the <Resource>).

I think the documentation is correct for the current version.

@slax57
Copy link
Contributor

slax57 commented Sep 15, 2022

@fzaninotto
I'm OK with the BC: let's not change the code.

However I disagree regarding the docs.
Currently they say that the default value for AutocompleteInput's optionText is "name", but actually it's "whatever your recordRepresentation is". So this should be changed in the docs IMO.

@fzaninotto
Copy link
Member

you're right! I didn't notice the default value of name in the props table. So let's fix that in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants