This is mentioned in #108 but I think it's gotten lost in the noise of that ticket (which is still relevant - the ReferenceInput is a really flakey component). In any case that thread seems to have been ignored so I'm creating a new one because this is causing me much pain (blocker).
Basically there seems to be no way to allow an empty value (i.e unselect something). According to the documentation this is done via the allowEmpty attribute, but setting this triggers an exception and kills the loading of the edit screen if the record being edited contains an entry for that field. If the record does not contain an entry the edit screen will load, but as soon as you select an option and save you will be unable to edit the record (as the exception is thrown).
If I remove allowEmpty (i.e set it to false) then if the field is blank instead of seeing the (select) component you just get the field label and then a blank gap. If it's not blank everything works, but once I can never clear that field (there is no option to select blank).
At least one other person seems to be having the same issue (@ilaif).
One final point - I am using a custom REST client. My backing store is a mongodb and my id's are prefixed with an underscore. I have updated my convertHTTPResponseToREST method to map response data with an id field. I've done this for all actions, but just in case this is related. #
I've found there is a glitch where sometimes it works. In my use case I have a collection of 2 users. Each user has an assigned owner. The owners are references that resolve {id, name}. One of the users has an owner and the other does not. When I set allowEmpty on the owner reference and attempt to load the user with an owner set it gives me an error. Then if I try to edit the other user I also get an error Cannot read property 'getHostNode' of null and my only option is to refresh the page.
If instead load the user with no owner first, I can edit the user. If i go back to the list view and attempt to edit the user with an owner set the edit screen loads without issue and I can edit my user.
I believe the difference in behaviour is that by loading an ownerless user I end up fetching the list of all owners and storing it in the redux store. After this loading the owned user reads from this store and everything is great. Hope this helps in tracking down the issue....
I needed to set optionValue on the child SelectInput. The documentation on the subject could be a little clearer...
<ReferenceInput label="Organisation" source="org" reference="orgs" allowEmpty={true}>
<SelectInput optionText="name" optionValue="id" />
</ReferenceInput>
optionText="name" optionValue="id" are the default values. There is actually a bug, reopening.