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

ReferenceInput allowEmpty impossible to give empty value

Open remi13131 opened this issue 9 years ago • 10 comments

Context: When having a ReferenceField with AutoCompleteInput already populated, and being in Edit

Actual behavior: if I want to delete the value given to this field (eg send null value to the API), and delete the text inside the field, the old value will be sent with the request on form submission. Hence it is impossible to "reset" this value.

Expected behavior: Being able to null out a ReferenceField already populated.

remi13131 avatar Apr 24 '17 14:04 remi13131

Have you added the allowEmpty prop to the ReferenceInput ?

djhi avatar May 09 '17 14:05 djhi

I just reproduced the problem with allowEmpty set

djhi avatar May 09 '17 14:05 djhi

Related to https://github.com/callemall/material-ui/issues/6702

In the meantime, a solution would be to have a custom AutoCompleteInput with a clear button

djhi avatar May 09 '17 15:05 djhi

It looks like issue been resolved on material-ui side, but it still doesn't work in react-admin

RusinovAnton avatar Mar 25 '19 13:03 RusinovAnton

Not ReferenceInputController neither AutoCompleteInput components do not use allowEmpty prop at all :(

RusinovAnton avatar Mar 25 '19 13:03 RusinovAnton

The problem is not that AutoCompleteInput didn't have "onblur" handler but that the ReferenceInputController doesn't pass down empty choice. For example, the SelectInput component does it itself.

RusinovAnton avatar Mar 25 '19 13:03 RusinovAnton

@RusinovAnton seems the issue is still present right? @djhi can we reopen it? https://github.com/mui-org/material-ui/issues/6702 has been closed but it's still not working, I've tried to add allowEmpty to both ReferenceInput and AutocompleteInput but it still doesn't show the empty value

alex88 avatar Sep 24 '19 05:09 alex88

The problem is still here and seems to be on the react-admin side : using a SelectInput you have a first row that is empty with allowEmpty. There is no empty row with the AutocompleteInput and this is where the bug lies in my opinion.

You can verify this behavior when you do not type anything but just click on the input, it will show a list with no empty option. I understand that it may be inconvenient to have an empty row when typing even though the usual use case appears to be when the field is filled (like in an edit view) and you want to empty it.

It would be really nice from you guys to reopen this issue to work on a solution.

boutdemousse avatar Nov 12 '19 08:11 boutdemousse

Please open a new issue following the issue template. Besides, I think this is fixed in 3.0.

fzaninotto avatar Nov 12 '19 15:11 fzaninotto

the same issue here. Version 4.1

ikonduktor avatar May 31 '22 19:05 ikonduktor