jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

Support UI Schema rule array

Open kchobantonov opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Currently we can add only one rule per control which has only one effect. We can have cases where a control could become hidden, visible, enabled or disabled based on different rules.

Describe the solution you'd like

In UISchemaElement change

rule?: Rule;

to

rule?: Rule | Rule[];

Describe alternatives you've considered

Currently a work around would be to use a layout container that have another rule attached but if we have all 4 rules that applies then we should have 3 dummy containers/layouts around the control just to make that work.

Framework

Core

RendererSet

No response

Additional context

No response

kchobantonov avatar Sep 22 '21 22:09 kchobantonov

Hi @kchobantonov, this proposal definitely makes sense to me.

Note however that the only valid case at the moment is to have a maximum of two different rules. One for the enabled state and one for the visible state. The reason is that each rule always works in two ways. A SHOW rule will set visible: true if it applies and visible: false if it doesn't, while a HIDE rule will do the exact opposite. Having both a SHOW and a HIDE rule they'll conflict. The same is true for the ENABLE and DISABLE rules. So if you really need both kind of rules on the same element the workaround only consists of one additional layout.

Once we allow an array of rules we have to decide what happens when conflicting rules are given.

sdirix avatar Sep 23 '21 07:09 sdirix

Yes you are correct regarding the need for only 2 rules for now. Also if you specify conflicting rules then we can only select the first one - e.g. if we have ENABLE and DISABLE rule then we can always pick the first such rule and ignore the other one to be consistent.

kchobantonov avatar Sep 23 '21 12:09 kchobantonov