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

Unable to use if else with required properties #1456

Open
krishgcek opened this issue Jan 3, 2024 · 2 comments
Open

Unable to use if else with required properties #1456

krishgcek opened this issue Jan 3, 2024 · 2 comments
Assignees

Comments

@krishgcek
Copy link

krishgcek commented Jan 3, 2024

I was trying to use the react example, https://rjsf-team.github.io/react-jsonschema-form/ if then else in json-editor interactive playground.

When I change from cat to fish the options did came. But it was not an enum. I also had trouble with values. The expectation is to remove the additional property when the option is changed from fish to cat again. react version has options like, Omit extra data and Live omit. Is there something similar available here.

schema used,

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

[edit] added formatting

@schmunk42
Copy link
Collaborator

@krishgcek Could you double check the schema, the required part at the end looks wrong.

CC: @germanbisurgi Is it supported to set properties (in form root), based on other properties?

@eduo
Copy link

eduo commented Mar 4, 2024

Subscribing, since I'm in the same situation where I want to change the defaultProperties depending on a root.something value chosen from an enum.

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

4 participants