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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

New enumTitles not working => old enumNames have warnings 鈿狅笍 that are depreciated 馃悰 #4072

Open
4 tasks done
Fremen1990 opened this issue Jan 31, 2024 · 2 comments

Comments

@Fremen1990
Copy link

Fremen1990 commented Jan 31, 2024

Prerequisites

What theme are you using?

material-ui

Version

5.16.1

Current Behavior

Current state:

I use currently JSON Schema with enumNames but in DevTools it is shouting that enumNames are depreciated 鈿狅笍 and will be removed and to use enumTitles.

(console warnings 鈿狅笍 are extremaly long and plenty of them)

image


After trying to change to enumTitles:

After changing to enumTitles I have the same label and value in my inputs and I do not have my input label which was normally working when it was under enumNames

image

image

Expected Behavior

To have label from enumTitles and value from enum => to just have working enumTitles like enumNames (depreciated) is working

Steps To Reproduce

Reproduce console warnings 鈿狅笍

You can reproduce console warnings 鈿狅笍 just using enumNames in local environment and devTools will shout as loud as possible 馃槄


Reproduce enumTitles not working as labels

You can check if enumTitles not working you can just paste this example JSON Schema into playground:

https://rjsf-team.github.io/react-jsonschema-form/

{
  "title": "Color Selector",
  "type": "object",
  "properties": {
    "favoriteColor": {
      "type": "string",
      "title": "Choose your favorite color",
      "enum": [
        "red",
        "green",
        "blue"
      ],
      "enumTitles": [
        "Red like a fire",
        "Green like a grass",
        "Blue like an ocean"
      ]
    }
  },
  "required": [
    "favoriteColor"
  ]
}

Environment

- OS: Windows 11
- Node: 18.1
- pnpm: 8.14

Anything else?

No response

@Fremen1990 Fremen1990 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jan 31, 2024
@Stusu
Copy link

Stusu commented Feb 1, 2024

Hi @Fremen1990, there is no bug with enum titles. It is not just replaced name, but also structure. You should make a little more changes in your schema - replace enum with oneOf.

It is described in documentation

It should looks like that:

{
  "title": "Color Selector",
  "type": "object",
  "properties": {
    "favoriteColor": {
      "type": "string",
      "title": "Choose your favorite color",
      "oneOf": [
         { "const": "red", "title":  "Red like a fire" },
         { "const": "green", "title": "Green like a grass" },
         { "const": "blue", "title": "Blue like an ocean" }
      ]
    }
  },
  "required": [
    "favoriteColor"
  ]
}

@heath-freenome heath-freenome added question awaiting response and removed bug needs triage Initial label given, to be assigned correct labels and assigned labels Feb 2, 2024
@heath-freenome
Copy link
Member

@Stusu Thanks for answering the question! @Fremen1990 the solution provided is the preferred approach to providing names for enums. enumNames was a hack that was added early on in RJSF and is expected to be removed in the next major release.

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

No branches or pull requests

3 participants