ReferenceInput and SelectInput showing "Associated reference no longer appears to be available."
What you were expecting: SelectInput to populate with the selected value.
What happened instead: SelectInput is populated with the selected value. However, underneath it shows "Associated reference no longer appears to be available."
My form looks like this:
export const TemplateEdit = props => (
<Edit {...props}>
<SimpleForm>
<TextInput source="name" />
<ArrayInput label="Shots" source="shots">
<SimpleFormIterator>
<TextInput source="name" />
<ReferenceInput
source="shotType"
reference="shot-types"
>
<SelectInput optionText="name" optionValue="@id" />
</ReferenceInput>
</SimpleFormIterator>
</ArrayInput>
</SimpleForm>
</Edit>
);
The API returns the value "/shot-types/1" for "shotType". The response to populate the dropdown looks like this:
[
{
"@id": "/shot-types/1",
"@type": "ShotType",
"id": 1,
"name": "Shot Type 1"
},
{
"@id": "/shot-types/2",
"@type": "ShotType",
"id": 2,
"name": "Shot Type 2"
}
]
Here is a screenshot of what occurs:

It's strange that the value shows as selected but the warning appears saying it no longer exists.
Fyi, select input saves correctly and everything works. It just shows that warning saying it isn't available (but it matches it correctly).
I've never used a ReferenceInput inside an ArrayInput, so it's not tested. Would you mind setting up a CodeSandbox to show the issue?
This occurs outside an ArrayInput as well.
I found a stackoverflow where someone else is trying to use a different optionvalue as well: https://stackoverflow.com/questions/51021661/react-admin-using-field-other-than-id-for-referenceinput
It's like optionValue doesn't work properly on the ReferenceInput child.
@fzaninotto I could resolve the issue by converting the value before ReferenceInput gets it. Is there a way I could do this?
Basically I just need to convert /shot-types/2 to 2 and it will resolve everything.
I just used the parse and format property on ReferenceInput. There is still a problem with optionValue not working properly though.
Code below if anyone else is looking for a quick solution
const formatIriAsInt = v => {
if (v.indexOf('/') >= 0) {
v = v.split('/');
return parseInt(v[v.length - 1]);
}
return v;
}
<ReferenceInput
source="shotTypes"
reference="shot-types"
parse={v => v ? '/organisations/' + v : v}
format={formatIriAsInt}
{...rest}>
<SelectInput optionText="name" />
</ReferenceInput>
Again, please provide a minimal CodeSandbox to let us reproduce the issue.
@trsteel88 just out of curiosity - if you render many references ( based on ReferenceInput ) does each one call your API?
@matigda No, in that case, we accumulate the individual GET_ONE calls into a single GET_MANY
@djhi hi, thank you very much for that quick response. I know it says so in the docs, but this piece of code:
export const SliderEdit = props => (
<Edit {...props}>
<SimpleForm>
<TextField source="id" label={'Id'}/>
<LongTextInput source="name" />
<NumberInput source="status" />
<ArrayInput source="bannerSliders">
<SimpleFormIterator>
<ReferenceInput label="Banner" source="banner.id" reference="banners">
<SelectInput optionText="name" />
</ReferenceInput>
<NumberInput source="position" />
</SimpleFormIterator>
</ArrayInput>
</SimpleForm>
</Edit>
);
makes a call for each ReferenceInput. So that's why I asked author. Sorry for messing up the issue. I've already created the issue on StackOverflow: https://stackoverflow.com/questions/54632761/is-there-any-cache-in-react-admin/54642028
I was experiencing the same issue as @trsteel88; I was trying to reference a different Resource using a different value to "id" and passing an optionValue.
The ReferenceInput all worked fine. I needed a quick fix in an edit page, so hid the FormHelperTextProps on the field (see below). Obviously this is hacky, and wouldn't typically advocate .
#edit.js:
<SelectInput
FormHelperTextProps={{ classes: { root: 'hide-helper' } }}
optionText="name"
optionValue="iconKey"
/>
#index.css:
.hide-helper {
display: none;
}```
Since that level of overlapping doesn't seem to be a common need, and that no CodeSandbox were provide in order to help us reproduce the issue, I'm closing this one.
Feel free to re-open with a CodeSandbox.
I'm able to reproduce that problem using CodeSandbox. If you look into console it'll show 3 queries to REST that are absolutely identical.
<ReferenceInput label="Banner" source="banner.id" reference="banners">
<SelectInput optionText="name" />
</ReferenceInput>
when we use this, how can we catch its value, as banner.id or as something else?