ngx-schema-form
ngx-schema-form copied to clipboard
Visible If not working if value is [0]
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] }, }
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?
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.
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"