ngx-schema-form icon indicating copy to clipboard operation
ngx-schema-form copied to clipboard

Visible If not working if value is [0]

Open AleksaDursun opened this issue 3 years ago • 3 comments

When my selectField value is 0 the schema does not render the fields that have visibleIf: {selectField: [0]}. This is the code in my schema. { type: 'array', title: 'Columns', items: { type: 'object', properties: { color: { type: 'string', description: 'Color', widget: 'color-picker', } }, }, visibleIf: { selectField: [0] }, }

AleksaDursun avatar Jan 27 '22 08:01 AleksaDursun

A working example on Stackblitz (click) for your schema:

{
  "type": "object",
  "properties": {
    "selectField": {
      "type": "string",
      "widget": "select",
      "oneOf": [
        {
          "enum": ["0"],
          "description": "Zero"
        },
        {
          "enum": ["1"],
          "description": "One"
        }
      ]
    },
    "columns": {
      "type": "array",
      "title": "Columns",
      "items": {
        "type": "object",
        "properties": {
          "color": {
            "type": "string",
            "description": "Color",
            "widget": "color-picker"
          }
        }
      },
      "visibleIf": {
        "selectField": [0]
      }
    }
  }
}

@AleksaDursun would you take a look on it?

daniele-pecora avatar Feb 08 '22 18:02 daniele-pecora

That is the workaround I found as well, but the issue still persists. If the value is equal to 0 (number zero) it does not work.

AleksaDursun avatar Feb 09 '22 12:02 AleksaDursun

Got the same problem. As far as I can tell it's related to this line: https://github.com/guillotinaweb/ngx-schema-form/blob/f80c7a5b0646828dc3ab16973c0f3ecbf938467a/projects/schema-form/src/lib/model/formproperty.ts#L252

The truth value of variable value is false if it is equal to the number 0 and double negation still makes it false. This is probably to check if there is no null or undefined in the variable value but this also makes the values NaN, number 0, boolean false and empty string '' to not pass this check.

My workaround is to use "$EXP$ target.value == 0"

KBroichhausen avatar Jul 11 '22 11:07 KBroichhausen