Field is initially displayed, even if condition that should SHOW field is initially not met

In my opinion, field “fieldForOther” with label “If other:” should not be initially displayed.
init

If I un-select checkbox “Other”, input “If other”: disappears. If I select it once again, input is displayed, so it works. But it does not work initially.

schema:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "someArray": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "enum": [  "A", "B", "Other" ]
      }
    },
    "fieldForOther": {
      "type": "string"
    }
  }
}

uischema

{
  "type": "Categorization",
  "elements": [
    {
      "label": "Some Form",
      "type": "Category",
      "elements": [
        {
          "label": "Some Form",
          "type": "Group",
          "elements": [
            {
              "scope": "#/properties/someArray",
              "label": "Select at least one",
              "type": "Control"
            },
            {
              "scope": "#/properties/fieldForOther",
              "label": "If other",
              "options": {
                "multi": true,
                "minRows": 3
              },
              "rule": {
                "effect": "SHOW",
                "condition": {
                  "scope": "#/properties/someArray",
                  "schema": {
                    "contains": {
                      "const": "Other"
                    }
                  }
                }
              },
              "type": "Control"
            }
          ]
        }
      ]
    }
  ]
}

Hi @marwoj,

To explicitly define what shall happen when the value is undefined you can point the condition to the parent scope and define a required in the condition schema. See this question for an example.

Hi @sdirix
I’ve udpated scope and added required to schema (see comments below).
Maybe I miss something, but still it doesn’t work.

Did you mean:

{
  "type": "Categorization",
  "elements": [
    {
      "label": "Some Form",
      "type": "Category",
      "elements": [
        {
          "label": "Some Form",
          "type": "Group",
          "elements": [
            {
              "scope": "#/properties/someArray",
              "label": "Select at least one",
              "type": "Control"
            },
            {
              "scope": "#/properties/fieldForOther",
              "label": "If other",
              "options": {
                "multi": true,
                "minRows": 3
              },
              "rule": {
                "effect": "SHOW",
                "condition": {
                  "scope": "#", // changed scope
                  "schema": {
                    "contains": {
                      "const": "Other"
                    },
                    "required":["someArray"] // added required
                  }
                }
              },
              "type": "Control"
            }
          ]
        }
      ]
    }
  ]
}

Hi @marwoj,

As you now refer to the parent scope you now also need to move the contains back to the nested array, e.g.

"schema": {
  "properties": {
    "someArray": {
       "contains": {
         "const": "Other"
      }
    }
  },
  "required":["someArray"]
}

Thank you very much @sdirix ,now it works as expected.