rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.34k stars 2.19k forks source link

Nested dependencies not updated correctly #1235

Closed Sh1d0w closed 5 years ago

Sh1d0w commented 5 years ago

Prerequisites

Description

When there are nested dependencies, updating top most dependency does not properly update form data for the nested ones, resulting incorrect form rendering.

Steps to Reproduce

  1. Open this form
  2. Check employee accounts
  3. From update absences select BOTH
  4. Permitted Extension appears correctly
  5. Now uncheck employee accounts
  6. Permitted Extension still shows, but it should not because it is dependency of update absences, which should only shows when employee accounts is true.

Expected behavior

Permitted Extension should be hidden and all form data related to those nested dependencies removed.

Actual behavior

Permitted Extension still shows and the value of update absences is in the form data

Version

1.3.0

lunaceee commented 2 years ago

@epicfaace I'm having a similar issue updating nested dependencies. Here's my code:

{
  "type": "object",
  "title": "Jira schema",
  "properties": {
    "summary": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "project": {
      "type": "string",
      "enum": [
        "BE",
        "FE"
      ],
      "enumNames": [
        "Backend Sprint",
        "Frontend Sprint"
      ],
      "default": "BE"
    }
  },
  "required": [
    "project"
  ],
  "dependencies": {
    "project": {
      "oneOf": [
        {
          "properties": {
            "project": {
              "enum": [
                "BE"
              ]
            },
            "issuetype": {
              "enum": [
                "10001",
                "10002"
              ],
              "enumNames": [
                "Task",
                "Story"
              ],
              "default": "10001"
            }
          },
          "required": [
            "issuetype"
          ]
        },
        {
          "properties": {
            "project": {
              "enum": [
                "FE"
              ]
            },
            "issuetype": {
              "type": "string",
              "title": "Issue Type",
              "enum": [
                "10003",
                "10004"
              ],
              "enumNames": [
                "Epic",
                "Bug"
              ],
              "default": "10003"
            }
          },
          "required": [
            "issuetype"
          ]
        }
      ]
    },
    "issuetype": {
      "oneOf": [
        {
          "properties": {
            "priority": {
              "enum": [
                "1",
                "2",
                "3"
              ],
              "enumNames": [
                "High",
                "Medium",
                "Low"
              ],
              "default": "1"
            },
            "issuetype": {
              "enum": [
                "10001"
              ],
              "enumNames": [
                "Task"
              ]
            }
          }
        },
        {
          "properties": {
            "priority": {
              "enum": [
                "2",
                "3"
              ],
              "enumNames": [
                "Medium",
                "Low"
              ],
              "default": "2"
            },
            "issuetype": {
              "enum": [
                "10002"
              ],
              "enumNames": [
                "Story"
              ]
            }
          }
        },
        {
          "properties": {
            "priority": {
              "enum": [
                "3"
              ],
              "enumNames": [
                "Low"
              ],
              "default": "3"
            },
            "issuetype": {
              "enum": [
                "10003"
              ],
              "enumNames": [
                "Epic"
              ]
            }
          }
        }
      ]
    }
  }
}

When I update project, priority won't get updated. The main differences here is that I'm using enum instead of oneOf so not sure if that's the problem. But I am hoping to stick to enum if possible. Appreciated if you can take a look at this. Thanks!