Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visible If not working if value is [0] #431

Open
AleksaDursun opened this issue Jan 27, 2022 · 3 comments
Open

Visible If not working if value is [0] #431

AleksaDursun opened this issue Jan 27, 2022 · 3 comments

Comments

@AleksaDursun
Copy link

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] }, }

@daniele-pecora
Copy link
Collaborator

daniele-pecora commented Feb 8, 2022

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?

@AleksaDursun
Copy link
Author

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.

@KBroichhausen
Copy link
Contributor

Got the same problem.
As far as I can tell it's related to this line:

valid = !!value ? `${expString}` === `${value}` : false;

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"

akanduru added a commit to LHNCBC/ngx-schema-form that referenced this issue Oct 28, 2022
…m upgrade-to-angular14 to master

* commit '3e264e578a104328c3137715e2c446077c99aff6': (38 commits)
  version 2.8.4
  Prevent multiple calls of _bindVisibility for the same elements when traversing the tree structure
  version 2.8.3
  Fixed Two-way data binding when using visibleIf
  Fixed typo in README and removed doubling of words
  version 2.8.2
  feat: Added chainable oneOf and allOf in visibleIf
  fix dep versions
  Bump minimist from 1.2.5 to 1.2.6
  Upgrade to Angular 14, fix guillotinaweb#443
  version 2.7.2
  Fix for  guillotinaweb#431
  Use DisableControlDirective for widgets to remove warnings for reactive forms.
  Changed cp command in build:lib to use ncp because there is no cp on windows machines.
  version 2.7.1
  Add nullable schema.title check
  Bump karma from 6.3.14 to 6.3.16
  Bump follow-redirects from 1.14.7 to 1.14.8
  Bump karma from 6.3.9 to 6.3.14
  Built-in ability to let compile the schema so defs and refs get resolved
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants