rjsf-team/react-jsonschema-form

Nested dependencies not updated correctly

Closed

#3,450 opened on Feb 21, 2023

 (18 comments) (1 reaction) (0 assignees)TypeScript (2,136 forks)batch import
any-one-all-ofbughelp wantedutils

Repository metrics

Stars
 (13,175 stars)
PR merge metrics
 (Avg merge 3d 17h) (32 merged PRs in 30d)

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