Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectInput ignores emptyValue property #8060

Closed
dylanlt opened this issue Aug 10, 2022 · 6 comments · Fixed by #8234
Closed

SelectInput ignores emptyValue property #8060

dylanlt opened this issue Aug 10, 2022 · 6 comments · Fixed by #8234
Labels

Comments

@dylanlt
Copy link

dylanlt commented Aug 10, 2022

What you were expecting:
The emptyValue is sent when the empty option is selected in a SelectInput.

What happened instead:
An empty string is sent.

Steps to reproduce:
Add emptyValue={null} property to a SelectInput.

Related code:

<ReferenceInput source="assignedToId"	reference="users">
	<SelectInput optionText="username" emptyValue={null} />
</ReferenceInput>

When the form loads, {assignedToId: null, ...} is received, but when the user clicks save then the form sends {assignedToId: '', ...}

Environment

  • React-admin version: 4.2.6
  • Last version that did not exhibit the issue (if applicable):
  • React version: 18.2.0
  • Browser: Chrome
  • Stack trace (in case of a JS error):
@fzaninotto
Copy link
Member

Thanks for your report. Would you mind adding a reproduction based on the simple example codesandbox?

https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple

@dylanlt
Copy link
Author

dylanlt commented Aug 11, 2022

https://codesandbox.io/s/lucid-haibt-b0p0zm?file=/src/posts/PostEdit.tsx

See the example with editing a post. A user select input is at the bottom of the first tab of the edit form. In the console, the object is seen to have { user_id: "", ... }. This happens regardless of the value received from the data provider.

@takayamaki
Copy link

I encount this problem too.

I tried some cases.

emptyValue="foo" => got "foo"

emptyValue="null" => ignored, got ""
emptyValue={null} => ignored, got ""

emptyValue="1" => got "1"
emptyValue={1} => ignored, got ""

emptyValue="true" => ignored, got ""
emptyValue=true => got true

@dylanlt
Copy link
Author

dylanlt commented Oct 4, 2022

A code sandbox was added to this ticket 2 months ago can the tag "needs more info" be removed, please?

@fzaninotto
Copy link
Member

The empty value of a SelectInput inside ReferenceInput is set to null by default since version 4.4.0, see #8188. So using emptyValue shouldn't be necessary in this case.

There is a remaining bug, which is that if a record has no value for a reference and the user doesn't update it, <SelectInput> and <ReferenceInput> still turn the reference value to empty string.

So I'm marking this a s a bug.

@fzaninotto
Copy link
Member

fzaninotto commented Oct 5, 2022

Besides, <SelectInput> shouldn't accept null as a possible emptyValue - see #8235.

JinParc pushed a commit to JinParc/react-admin that referenced this issue Oct 25, 2022
JinParc pushed a commit to JinParc/react-admin that referenced this issue Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants