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

Enum enumNames are not applied to null values #2900

Open
4 tasks done
f4irline opened this issue Jun 30, 2022 · 6 comments
Open
4 tasks done

Enum enumNames are not applied to null values #2900

f4irline opened this issue Jun 30, 2022 · 6 comments
Assignees
Labels
bug defaults p1 Important to fix soon

Comments

@f4irline
Copy link

Prerequisites

What theme are you using?

core

Version

4.2.0

Current Behavior

I have a field with number enums, which should be nullable. I've specified the type to be ["number", "null"]. I'm also using enumNames property to give the values different titles. My schema is this:

{
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "required": [
    "favoriteColor"
  ],
  "properties": {
    "favoriteColor": {
      "type": ["number", "null"],
      "title": "Favorite Color",
      "enum": [
        0,
        1,
        2,
        null
      ],
      "enumNames": [
        "Red",
        "Green",
        "Blue",
        "None"
      ]
    },
    "default": null
  }
}

But when I choose the null ("None") value, the data doesn't give the field value null. Instead it gives it value "None". For other values it works, for example if I choose the value "Red", the value is 0 as it should. I'm seeing this behavior with type: ["string", "null"] as well.

I've also tried providing the following UISchema with no luck:

{
  "favoriteColor": {
    "ui:emptyValue": null
  }
}

Expected Behavior

enumNames should also map names for null values.

Steps To Reproduce

  1. Create a schema with a property with type: ["number", "null"]
  2. Give the property some enum values. Leave one of them null.
  3. Give the property some enumNames. You could name the null value for example "Empty".
  4. Select the null value (with the name "Empty").
  5. You should see that the value is not null as expected, but "Empty".

Environment

- OS: MacOS
- Node: 14.19.1
- npm: 6.14.6

Anything else?

Link to the RJSF playground: here

@f4irline f4irline added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jun 30, 2022
@f4irline
Copy link
Author

This actually seems to work as expected with the semantic-ui and both material-ui themes (4 and 5). With other themes either the value is given the enumName, or "null" (which is also incorrect, because it should be null)

@f4irline
Copy link
Author

The issue with semantic-ui and material-ui themes is that the field is emptied when the null value is selected:
image

Even though it should say "None", because that is the given enumName

@heath-freenome
Copy link
Member

@f4irline I'm sorry to say but enumNames support is being dropped in version 5 as there are options that work with oneOf (see #532 for how to do it).

@heath-freenome heath-freenome added possibly close To confirm if this issue can be closed and removed needs triage Initial label given, to be assigned correct labels and assigned labels Aug 22, 2022
@f4irline
Copy link
Author

@f4irline I'm sorry to say but enumNames support is being dropped in version 5 as there are options that work with oneOf (see #532 for how to do it).

That's alright. But I'm seeing the same behaviour with oneOf as well, see RJSF playground here

@Sinled
Copy link

Sinled commented Dec 2, 2022

Any updates on this? I also have this problem with null transformed to string, and can't solve it with oneOf

@heath-freenome heath-freenome added defaults p1 Important to fix soon and removed possibly close To confirm if this issue can be closed labels Apr 14, 2023
@nickgros
Copy link
Contributor

@f4irline I'm sorry to say but enumNames support is being dropped in version 5 as there are options that work with oneOf (see #532 for how to do it).

That's alright. But I'm seeing the same behaviour with oneOf as well, see RJSF playground here

The issue in the above playground seems to go away if the default entry is the schema is removed, so that may be the source of one of the bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug defaults p1 Important to fix soon
Projects
None yet
Development

No branches or pull requests

6 participants