guillotinaweb / ngx-schema-form

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

"visibleIf" with nothing vs. "oneOf" #445

Open KBroichhausen opened 2 years ago

KBroichhausen commented 2 years ago

I have an object Object 2 which only should be visible if: Field 1 is equal to value Value 1 or Field 2 is equal to value 1.

Now, add some extra: Field 2 is only visible if Field 1 is equal to Value 2 or Value 3.

This simply means that Object 2 is mandatory for Value 1 and is optional for Value 2 and Value 3, which can be toggled via Field 2.

Sounds too complicated...here is a stackblitz: https://stackblitz.com/edit/angular-ivy-ymrftk

As you can see, Schema 1 contains oneOf for Object 2 in visibleIf and is rendered without Object 2 and Schema 2 does not contain oneOf but Object 2 is rendered. If you flip-flop in Schema 1 to e.g. Value 2 and back to Value 1, you are back at initial state but now Object 2 is visible.

This does not look like it is intended. I would create a PR but currently I do not know why there is different logic for oneOf and without oneOf because I thought this should be equivalent in my case. It looks like the not visible element in the oneOf part triggers the setVisible method with false.