When using <ReferenceInput /> with the allowEmpty={true}, the AutocompleteInput child will not display any selected value if the referenced object wasn't already in the redux-store when the component mounted.
Ex:
<ReferenceInput
source="related_song.id"
label="Related song"
reference="song"
allowEmpty={true} // Works fine if set to false
>
<AutocompleteInput optionText={song_title}/>
</ReferenceInput>
admin.resources.song.data[related_song.id] already exist in the store when mounting the AutocompleteInput component, everything works fine and the AutocompleteInput displays the admin.resources.song.data[related_song.id] as the selected value.admin.resources.song.data[related_song.id] doesn't exist yet in the store when mounting the AutocompleteInput component, the referenced song data will be fetched and added to the store but the AutocompleteInput will not display any selected value.What you were expecting:
The input should be populated with the existing value even when the reference data is fetched after the input has been mounted.
What happened instead:
The input stays empty if the data of the reference is not in the redux store when the input component mount.
Steps to reproduce:
// inside CommentEdit.js
<ReferenceInput
source="post_id"
reference="posts"
perPage={5}
sort={{ field: 'title', order: 'ASC' }}
allowEmpty={true}
>
<AutocompleteInput optionText="title" />
</ReferenceInput>
ReferenceInput (using allowEmpty={true}!) and anAutocompleteInput referencing posts resource.Other information:
data.js.componentWillReceiveProps of the AutocompleteInput components which will only call setSearchText if this.props.input.value !== nextProps.input.value ignoring the fact that when wrapped inside a ReferenceInput this.props.choices will change overtime as well.Environment
I confirm I have this issue too. When I refresh the single resource page, the reference input field doesn't have a value. If I click the list page and then go back to the resource it works.
I got this issue too. I think when we enter the editing page, the choices are not yet loaded and the saved value cannot be found in choices array ( empty ), therefore empty value is displayed in the field.
I got similar issue while using selectInput inside referencInput, i solved it by connecting my edit component to state:
export const Edit = connect(state => ({
record: state.form['record-form'] ? state.form['record-form'].values : null,
}))(EditComponent);
and then setting key in referenceinput like this:
key={props.record ? props.record.someValue : ''}
Can't reproduce anymore with 1.3.4. Feel free to reopen if needed
Most helpful comment
I confirm I have this issue too. When I refresh the single resource page, the reference input field doesn't have a value. If I click the list page and then go back to the resource it works.