json-tools/json-form

Question: Rules

ottigerb opened this issue · 6 comments

Is there a way to have multiple rules?

I experimented with:

            {
                "type": "Control",
                "scope": "#/properties/zivilstand_seit",
                "label": "seit (Jahr)",
                "rule": {
                    "effect": "HIDE",
                    "condition": {
                      "type": "LEAF",
                      "scope": "#/properties/zivilstand",
                      "expectedValue": ["Ledig", ""]
                  }
                }
              }

Thanks!

1602 commented

If I understand your question correctly, you might need to use "enum" keyword of json schema, which lists array of possible values. This is an example: http://jsfiddle.net/jto26h1b/2/

...sorry if I was unclear. No - I have to HIDE the field if value = "Ledig" or value="" or value=undefined. Just to have multiple "expectedValues" - tried above to put them inside an array.

...also is it possible to display all the enum values in a select box? I guess this is a new widget.

1602 commented

to HIDE the field if value = "Ledig" or value=""

This is currently not possible in this module, but JSON Schema itself has possibility of validating such values, using oneOf keyword. In my early experiment I tried to cover this keyword, which turned up in a huge complexity and slowness, it was also unclear how to make this user-friendly. So I decided to step back and only cover simple cases, without caring of things like oneOf, anyOf, and dependencies.

display all the enum values in a select box

Yes, that's a good idea. I will add it to a roadmap.

This is currently not possible in this module, but JSON Schema itself has possibility of validating such values, using oneOf keyword. In my early experiment I tried to cover this keyword, which turned up in a huge complexity and slowness, it was also unclear how to make this user-friendly. So I decided to step back and only cover simple cases, without caring of things like oneOf, anyOf, and dependencies.

Potentially it could be interesting to add another "schema" especially for UI purposes. Like other modules are doing. Example: https://jsonforms.io/docs/uischema. So all the look and feel could be done inside this "schema". So HIDE or oneOf stuff could be there - as https://jsonforms.io/docs/uischema/rules

1602 commented

I agree, having UI schema is necessary. There's a value in having feature to hide/disable form elements based on some conditions. Thanks for highlighting this!

Here's an issue where the progress will be tracked: #5