Rule works for enum but not oneOf

Hi,

I’m using a condition to hide a dropdown control depending on the value of other different dropdowns. This works as expected when the dropdown references data from an enum, but not when it’s sourced from a oneOf (i.e, the dropdown isn’t hidden). Is there something wrong with my syntax or is this not supported?

Refs (conditions works when this an enum, but not oneOf):

{
  "fetched_types": {
    "oneOf": [
      {
        "title": "placeholder",
        "const": "placeholder"
      }
    ]
  }
}

JSON Schema

{
  "properties": {
    "type": {
      "$ref": "#/definitions/fetched_types",
      "type": "string"
    }
  }
}

UI Schema

{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Control",
      "label": "Type",
      "scope": "#/properties/type",
      "rule": {
        "effect": "SHOW",
        "condition": {
          "scope": "#",
          "schema": {
            "anyOf": [
              {
                "properties": {
                  "options1": {
                    "enum": [
                      "Target Val"
                    ]
                  }
                }
              },
              {
                "properties": {
                  "options2": {
                    "enum": [
                      "Target Val"
                    ]
                  }
                }
              },
              {
                "properties": {
                  "options3": {
                    "enum": [
                      "Target Val"
                    ]
                  }
                }
              }
            ]
          }
        }
      }
    }
  ]
}

Hi @jsonformssean,

anyOf and non-existent properties often behave unexpectedly, I think this is also what happens for you.

I don’t fully understand the structure of your snippets. It would be better if you provide a full JSON Schema and UI Schema to reproduce the issue. These partial snippets mean that it’s much more work for us.

I condensed your snippets into this:

{
  "type": "object",
  "properties": {
    "options1": {
      "type": "string",
      "enum": ["Option1", "Target Val", "Option3"]
    },
    "options2": {
      "type": "string",
      "enum": ["Option1", "Target Val", "Option3"]
    },
    "options3": {
      "type": "string",
      "enum": ["Option1", "Target Val", "Option3"]
    },
    "type": {
      "$ref": "#/definitions/fetched_types"
    }
  },
  "definitions": {
    "fetched_types": {
      "oneOf": [
        {
          "title": "Placeholder",
          "const": "placeholder"
        },
        {
          "title": "Option A",
          "const": "optionA"
        },
        {
          "title": "Option B",
          "const": "optionB"
        }
      ]
    }
  }
}
{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Control",
      "label": "Options 1",
      "scope": "#/properties/options1"
    },
    {
      "type": "Control",
      "label": "Options 2",
      "scope": "#/properties/options2"
    },
    {
      "type": "Control",
      "label": "Options 3",
      "scope": "#/properties/options3"
    },
    {
      "type": "Control",
      "label": "Type",
      "scope": "#/properties/type",
      "rule": {
        "effect": "SHOW",
        "condition": {
          "scope": "#",
          "schema": {
            "anyOf": [
              {
                "properties": {
                  "options1": {
                    "const": "Target Val"
                  }
                }
              },
              {
                "properties": {
                  "options2": {
                    "const": "Target Val"
                  }
                }
              },
              {
                "properties": {
                  "options3": {
                    "const": "Target Val"
                  }
                }
              }
            ]
          }
        }
      }
    }
  ]
}

It then behaves like this:
AnyOfRules

  • data is empty, all three of the anyOf match as they are all valid
  • only once all properties are set to something different than Target Val the control vanishes because now none of them matches anymore

To fix the non-existing properties issue for you, you need to add required statement to the UI Schema rule:

"rule": {
        "effect": "SHOW",
        "condition": {
          "scope": "#",
          "schema": {
            "required": ["options1", "options2", "options3"],
            "anyOf": [
              {
                "properties": {
                  "options1": {
                    "const": "Target Val"
                  }
                }
              },
              {
                "properties": {
                  "options2": {
                    "const": "Target Val"
                  }
                }
              },
              {
                "properties": {
                  "options3": {
                    "const": "Target Val"
                  }
                }
              }
            ]
          }
        }