rjsf-team/react-jsonschema-form

Nested dependencies not updated correctly

Open

#3450 opened on Feb 21, 2023

View on GitHub
 (17 comments) (1 reaction) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
any-one-all-ofbughelp wantedutils

Description

Prerequisites

What theme are you using?

core

What is your question?

Playground

https://codesandbox.io/s/black-forest-bgkbeo?file=/src/App.js As example, conditinal schema property value not update as expected. when "animal" change to "Cat", "food" should be "meat".

schema.json

{
  "type": "object",
  "properties": {
    "animal": {
      "enum": ["Cat", "Fish"],
      "default": "Cat"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Cat"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "type": "string",
            "enum": ["meat", "grass", "fish"],
            "default": "meat"
          }
        },
        "required": ["food"]
      }
    },
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Fish"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "type": "string",
            "enum": ["insect", "worms"],
            "default": "insect"
          },
          "water": {
            "type": "string",
            "enum": ["lake", "sea"],
            "default": "lake"
          }
        },
        "required": ["food", "water"]
      }
    },
    {
      "required": ["animal"]
    }
  ]
}

Contributor guide