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

ui:emptyValue does not work with selects #1041

Closed
2 tasks done
elyobo opened this issue Oct 2, 2018 · 4 comments
Closed
2 tasks done

ui:emptyValue does not work with selects #1041

elyobo opened this issue Oct 2, 2018 · 4 comments

Comments

@elyobo
Copy link

elyobo commented Oct 2, 2018

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

ui:emptyValue is ignored for select widgets, requiring messy workarounds to resolve due to the way that the empty value option is injected.

The workaround that works is to specify a non-falsy empty value (e.g. "0") as the default for the form input (required in order to prevent the empty <option> from being injected), add your own empty value to the enum / enumNames (e.g. "0" as the value, "None" as the name), then reprocess to treat that empty value appropriately in the code dealing with the form (if "0" is OK then that's fine, but if you want a falsy default, e.g. an empty string, more work is required).

Obviously this is much more complex than just specifying ui:emptyValue with the desired value.

Steps to Reproduce

  1. Specify an enum field
  2. Specify it as a select field
  3. Give it a ui:emptyValue setting
  4. Select the empty option - the ui:emptyValue is not used

Simple playground reproduction

Expected behavior

The formData value should be the ui:emptyValue when the empty option is selected.

Actual behavior

There is no formData value for the field when the empty option is selected.

Version

Current playground version.

@diogoweb2
Copy link

Same problem here...
This problem triggers the warning:
"Warning: value prop on select should not be null. Consider using an empty string to clear the component or undefined for uncontrolled components."

"@material-ui/core": "3.2.2"

@abhishekpdubey
Copy link

I have similar issue with the enums. Here is the playground link

Based on the documentation here - https://react-jsonschema-form.readthedocs.io/en/latest/validation/#the-case-of-empty-strings
when enum is used with select widget, an empty option is added in the dropdown. This is not happening in the playground link I shared above.
And yes, ui:emptyValue does not work for me.
Also, ui:placeholder not working for me. I don't see "choose" in the Status dropdown.
Am I missing anything?

@thom4parisot
Copy link

thom4parisot commented Feb 25, 2021

As far as I can see, the processValue() method of SelectWidget returns undefined if a field is an empty string.

if (value === "") {
return undefined;

Is that it?

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Aug 18, 2022
- This is a reimplementation of rjsf-team#2251
- Fixes rjsf-team#1041
heath-freenome added a commit that referenced this issue Aug 19, 2022
* Use ui:emptyValue for SelectWidget
- This is a reimplementation of #2251
- Fixes #1041

* - Added `processSelectValue()` to `fluent-ui` for single select

* - Fixed documentation for `emptyValue`

* - Responded to self-feedback
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Aug 27, 2022
* Use ui:emptyValue for SelectWidget
- This is a reimplementation of rjsf-team#2251
- Fixes rjsf-team#1041

* - Added `processSelectValue()` to `fluent-ui` for single select

* - Fixed documentation for `emptyValue`

* - Responded to self-feedback
@heath-freenome
Copy link
Member

heath-freenome commented Aug 28, 2022

Fixed in v5 beta via #3026, see the 5.x migration guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants