react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

ReferenceInput label/source issue

Open jacky0707 opened this issue 2 years ago • 3 comments

What you were expecting:

label in <ReferenceInput > seems not working properly. I'm using version 4.1.1

What happened instead:

Steps to reproduce:

My code

<Create {...props}>
    <SimpleForm>
      <TextInput source='username' label='帳號' />
      <TextInput source='email' label='電子信箱' validate={validateEmail} />
      <ReferenceInput source='managedStoreId' reference='store' label='管理店家'>
        <SelectInput optionText='storeName' />
      </ReferenceInput>
      <PasswordInput source='password' label='密碼' />
    </SimpleForm>
</Create>

result image

And if I change the source in <ReferenceInput> like below

<Create {...props}>
  <SimpleForm>
    <TextInput source='username' label='帳號' />
    <TextInput source='email' label='電子信箱' validate={validateEmail} />
    <ReferenceInput source='管理店家' reference='store' label='管理店家'>
      <SelectInput optionText='storeName' />
    </ReferenceInput>
    <PasswordInput source='password' label='密碼' />
  </SimpleForm>
</Create>

result image

label is correct but '管理店家' is not a correct key.

Other information:

Environment "dependencies": { "ra-data-simple-rest": "^4.1.1", "react": "^18.1.0", "react-admin": "^4.1.1", "react-dom": "^18.1.0", "react-scripts": "5.0.1", },

  • Browser: chrome

jacky0707 avatar Jun 21 '22 15:06 jacky0707

Would you try?

<ReferenceInput source='managedStoreId' reference='store'>
   <SelectInput optionText='storeName' label='管理店家' />
</ReferenceInput>

As ReferenceInput is an input, it accepts a label but it will be ignored - we will update the doc to make it explicit. The displayed label will be the one given for its child.

antoinefricker avatar Jun 21 '22 16:06 antoinefricker

Please note that this is not the case when the <ReferenceInput> is used in filters. There, it also needs the label in the parent element too.

afilp avatar Jun 21 '22 23:06 afilp

Good catch! that's also why it's confusing.

fzaninotto avatar Jun 22 '22 08:06 fzaninotto

Would this be a case for using Labeled? @fzaninotto @septentrion-730n

ogustavo-pereira avatar Aug 31 '22 16:08 ogustavo-pereira