guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema
MIT License
485 stars 174 forks source link

`$ANY$ ` expressions do not validate correctly #414

Closed bennmapes closed 2 years ago

bennmapes commented 2 years ago

Currently when using an $ANY$ expression in a visibleIf statement it does not validate correctly on number fields or anything without a length property such as numbers, booleans etc.

The way it's currently testing for validity of a value with $ANY$ is with this: https://github.com/guillotinaweb/ngx-schema-form/blob/426af24763de06c4386e77add873281be407f5e3/projects/schema-form/src/lib/model/formproperty.ts#L253

I'm proposing we change that to something that can handle all possible values such as:

if(Array.isArray(value)) {
  valid = value.length > 0;
} else if(typeof value === "number") {
  valid = true;
} else if(typeof value === "boolean") {
  valid = true;
} else if(typeof value === "string") {
  valid = value !== '';
} else if(typeof value === "object") {
  valid = value !== null && value !== {};
}

Pull request with this change to follow. Feel free to share thoughts/improvements on this solution.