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

Limiting Drop-Down Values for Conditionally Constrained Schema #1587

Closed
3 tasks done
chapmanjw opened this issue Feb 10, 2020 · 2 comments
Closed
3 tasks done

Limiting Drop-Down Values for Conditionally Constrained Schema #1587

chapmanjw opened this issue Feb 10, 2020 · 2 comments

Comments

@chapmanjw
Copy link

Prerequisites

Description

For schema elements with enumerations that get conditionally constrained, the form library validates correctly, but still displays the enumeration values that are no longer valid.

I would expect that if an enumeration has 3 valid values, but is conditionally constrained to 2 of those, that only the 2 remaining valid values would be displayed.

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 Value",
          "enum": [
            "value1",
            "value2",
            "value3"
          ],
          "enumNames": [
            "Value 1",
            "Value 2",
            "Value 3"
          ],
          "type": "string"
        },
        "secondValue": {
          "title": "Second Enum Value",
          "enum": [
            "value4",
            "value5",
            "value6"
          ],
          "enumNames": [
            "Value 4",
            "Value 5",
            "Value 6"
          ],
          "type": "string"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "value": {
                "enum": [
                  "value1",
                  "value2"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "secondValue": {
                "enum": [
                  "value4",
                  "value5"
                ]
              }
            }
          },
          "else": {
            "properties": {
              "secondValue": {
                "enum": [
                  "value6"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Expected behavior

When selecting "Value 1" for "Enum Value", I would expect "Second Enum Value" to only display "Value 4" and "Value 5" as valid options rather than all of the original enum values.

Validation shows an error correctly when "Value 6" is selected, but I would expect preventing the user from selecting "Value 6" in the first place.

Actual behavior

"Value 6" is still displayed.

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

Version

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

@epicfaace
Copy link
Member

Your schema uses if/then/else which is not supported (#850). Perhaps you could achieve your objective by using dependencies and oneOf.

@chapmanjw
Copy link
Author

@epicfaace Other methods, such as anyOf or oneOf, create multiple schemas rather that limiting a single schema. This results in the second down-down-list to pick which schema to match to (like the example on this issue: #1586).

This provides a less-than-ideal user experience. Ideally, we'd have a way to limit values displayed in a single drop-down rather than multiple schemas.

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