rjsf-team/react-jsonschema-form

Use `enum` to populate dropdown list for object key

開放

#4,682 建立於 2025年7月1日

 (2 則留言) (2 個反應) (0 位負責人)TypeScript (2,136 個分叉)batch import
featurehelp wanted

倉庫指標

星標
 (13,175 顆星)
PR 合併指標
 (平均合併 3天 17小時) (30 天內合併 32 個 PR)

描述

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.

貢獻者指南