0

Here is the ref : Admin-on-Rest

in app.js :

<Resource name="customers" list={CustomerList} icon={UserIcon} edit={CustomerEdit} create={CustomerCreate}/>

in customer.js :

  <TextInput source="firstname" />
  <ReferenceInput label="Partner" source="id" reference="partners" >
      <AutocompleteInput optionText="name" />
  </ReferenceInput>
  <TextInput source="email" />

The problem is autocomplete not shown, but I check in log data retrieved from API end point /partners

And if I change reference to reference="customers", data and autocomplete shown.

Help please ??

Khalid
  • 887
  • 2
  • 13
  • 26

3 Answers3

3

You need another <Resource> for the relationship, even empty:

<Resource name="customers" list={CustomerList} icon={UserIcon} edit={CustomerEdit} create={CustomerCreate}/>
<Resource name="partners" />

It is well documented for <ReferenceField> (see the note), perhaps it needs the same note for <ReferenceInput>.

François Zaninotto
  • 7,068
  • 2
  • 35
  • 56
0

You <ReferenceInput reference="..."> needs to match the <Resource name="..."> for this to work. So this is the reason why reference="customers" worked for you.

If you want to get data from customers endpoints, but you want the label to be Partner you can specify it as label attribute on your ReferenceInput component, e.g. <ReferenceInput label="Partner" ...>.

Deividas
  • 6,437
  • 2
  • 26
  • 27
  • So the question is : is it possible to change ? the point is I need to get partner data. – Khalid Mar 02 '17 at 05:47
  • If you have an endpoint `customers`, you change the reference to `customers`. However, the label you display is up to you, so you can display `Partners`. Or do you want to access `partners` API endpoint? – Deividas Mar 02 '17 at 05:54
  • Yes I need get partners data on customers module. – Khalid Mar 02 '17 at 06:55
  • @Khalid I have updated my answer. Does specifying the `label` work for you? – Deividas Mar 02 '17 at 06:58
  • not work. what I know label only static word which's only displayed above of the input (Partners). – Khalid Mar 02 '17 at 07:00
  • Yes, I need get partners data in customers module – Khalid Mar 02 '17 at 07:04
  • @Khalid Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/137024/discussion-between-deividas-karzinauskas-and-khalid). – Deividas Mar 02 '17 at 07:05
0

The problem is probably the way you're importing your 'ReferenceInput' object. I had the same issue while creating my app and had no idea what is the problem. Check your import line and if it looks like this:

import {ReferenceInput} from "../../src/mui/input/ReferenceInput";

then change it to look this way:

import ReferenceInput from '../../src/mui/input/ReferenceInput';

Hope that helps you!

Number16BusShelter
  • 590
  • 2
  • 7
  • 17