guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create dependencies between parameter values?

Eviltux666 opened this issue · comments

I would like to define a dependency between two properties, so that certain values of a property are only displayed / can be choosen if another property is set to a certain value.

I know you can use visibleIf to show/hide a property completely, but what I would like to have is a visibleIf for a value.

Example:
properties:
food:
type: string
oneOf:
- description: Pizza
enum:
- pizza
- description: Pasta
enum:
- pasta
extras:
type: string
oneOf:
- description: extra cheese
enum:
- cheese
visibleIf:
food: pizza
- description: mushrooms
enum:
- mushrooms

In this example, I want to show both properties (food, extras), but the extras value "cheese" should only be visible, if "pizza" was selected as food.

How can you do that?

Unfortunately enum contained in oneOf of a visibleIf condition will not be processed for visibility.

But this could be handelt inside the validator.
Here a quick and dirty example that shows one way of how this could be achieved:
https://stackblitz.com/edit/ngx-schema-form-template-visibleif-enums?file=src%2Fapp%2Fmyform%2Fschema-form-validators.ts