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

Customizing Option 1, Option 2, etc. Drop-Down Labels Displayed When There Are Multiple Valid Schemas for a Schema Element #1586

Closed
3 tasks done
chapmanjw opened this issue Feb 10, 2020 · 1 comment

Comments

@chapmanjw
Copy link

Prerequisites

Description

When providing a schema element with multiple valid schemas, such as an element that has enumerated values but also accepts freeform strings, the form generator displays a drop-down list with each variation of the element.

Is there a way to customize the labels used for those drop-downs, instead of "Option 1", "Option 2", etc.?

Steps to Reproduce

Example Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "propertyA"
  ],
  "properties": {
    "propertyA": {
      "title": "Property A",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "title": "Enum with Freeform",
          "anyOf": [
            {
              "enum": [
                "value1",
                "value2",
                "value3"
              ],
              "enumNames": [
                "Value 1",
                "Value 2",
                "Value 3"
              ],
              "type": "string"
            },
            {
              "type": "string"
            }
          ]
        }
      }
    }
  }
}

Expected behavior

Ability to customize how the labels are derived.

Actual behavior

Displays a control with "Option 1" and "Option 2" that render each variation of the element.

Screen Shot 2020-02-10 at 1 57 08 PM

Screen Shot 2020-02-10 at 1 57 17 PM

Version

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

@epicfaace
Copy link
Member

Add the title attribute to each array item in anyOf.

Like this:

"anyOf": [
            {
              "title": "first title",
              "enum": [
                "value1",
                "value2",
                "value3"
              ],
              "enumNames": [
                "Value 1",
                "Value 2",
                "Value 3"
              ],
              "type": "string"
            },

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

No branches or pull requests

2 participants