Rule for multi-select enum not working

  1. A boolean to trigger “SHOW” a multi-select arrary.
    image
    image

  2. User select “foo” checkbox. It should “SHOW” a textfield below the multi-select array.
    image

schema.json

{
  "type": "object",
  "properties": {
"boolean":{
      "type":"boolean"
    },
    "multiEnum": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "enum": [
          "foo",
          "bar",
          "foobar"
        ]
      }
    },
    "textField":{
      "type":"string"
    }
}
}

uiSchema.json

{
  "type": "VerticalLayout",
  "elements": [
{
      "type": "Control",
      "scope": "#/properties/boolean"
    },
    {
      "type": "Control",
      "scope": "#/properties/multiEnum",
      "rule": {
        "effect": "SHOW",
        "condition": {
          "scope": "#properties/boolean",
          "schema": {
            "const": true
          }
        }
      }
    },
    {
      "type": "Control",
      "scope": "#/properties/textField",
      "rule": {
        "effect": "SHOW",
        "condition": {
          "scope": "#properties/multiEnum",
          "schema": { "enum": ["foo"] }
        }
      }
    }
 ]
}

Hi @newbieJson,

The condition.schema in the UI Schema does not match the JSON Schema, therefore it will never apply the "SHOW" rule, i.e.

  • The JSON Schema defines multiEnum as type: 'array', so valid values are for example ["foo", "bar"] and [].
  • In the UI Schema enum: ["foo"] is used, therefore the only valid value is "foo".

As one describes the value as an array and the other just as a single string this will never match.

If you want to match when only foo is selected then you could use enum: [["foo"]]. Then the only valid value is an array containing “foo”. If you want to match when foo is selected but any other value could be selected too, then you will need to enumerate all possibilities or use a not and enumerate all counter possibilities.

I can recommend online JSON Schema validators like this one so you can test your JSON Schemas before using them in JSON Forms.