Skip to content

Use enum to populate dropdown list for object keyΒ #4682

@anders-kiaer

Description

@anders-kiaer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions