rjsf-team/react-jsonschema-form

Use `enum` to populate dropdown list for object key

Open

#4682 opened on Jul 1, 2025

View on GitHub
 (2 comments) (2 reactions) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
featurehelp wanted

Description

Prerequisites

What theme are you using?

N/A

Is your feature request related to a problem? Please describe.

We have the following JSON schema structure:

{
  "additionalProperties": {
    "type": "string"
  },
  "propertyNames": {
    "enum": [
      "a",
      "b",
      "c",
      "d"
    ]
  },
  "type": "object"
}

The object keys have an enumerated list of allowed values.

react-jsonschema-form picks this enum correctly up in the validation: Image

However, as an end user it is difficult to understand from the generated user interface what is wrong, and what the allowed values are.

Describe the solution you'd like

When key is an enum with a defined list of allowed values, show it as a dropdown instead of a text input field, in order to support the user in filling in valid values.

Describe alternatives you've considered

Add the allowed values in the enum to the field description, such that the user have it documented. However, this has the risk of the description and the JSON schema enum field getting out of sync, and in addition it is quicker for the user to select a valid value from dropdown instead of parsing the description, and writing in a valid string.

Contributor guide