jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

Reference a property outside of the array

Open luiz290788 opened this issue 2 years ago • 2 comments

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

I need a way to reference a property outside of an array while evaluating a condition inside of the array.

Here is my example:

schema

{
  "type": "object",
  "properties": {
    "a": {
      "type": "string",
      "enum": ["Yes", "No"]
    },

    "b": {
      "type": "array",
      "minItems": 1,
      "maxItems": 5,
      "items": {
        "type": "object",
        "properties": {
          "c": { "type": "string" },
          "d": { "type": "string" }
        },
        "required": ["c"]
      }
    }
  },
  "required": ["a", "b"]
}

uischema

{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Control",
      "scope": "#/properties/a" <-- How to reference this value from inside of the array?
    },
    {
      "type": "Control",
      "scope": "#/properties/b",
      "options": {
        "detail": {
          "type": "VerticalLayout",
          "elements": [
            { "type": "Control", "scope": "#/properties/c" },
            {
              "type": "Control",
              "scope": "#/properties/d",
              "rule": {
                "effect": "SHOW",
                "condition": {
                  "scope": "#/properties/a", <-- I want the condition to be here
                  "schema": { "const": "Yes" }
                }
              }
            }
          ]
        }
      }
    }
  ]
}

I was able to reference other values in the same item of the array, which I will need as well, but is there a way to reference values outside of the array item? It looks like that all paths in the array are scoped to that specific array item.

Describe the solution you'd like

A way to specify a that a path is in the current item of the array or outside of the array. Both cases are valid and should be allowed.

Describe alternatives you've considered

I can (I will probably do that in my application) explode the items of the array into individual items so I can reference things outside of it. The problem is that I lose all the controls and ui elements for controlling the array. I will need to implement that manually.

Framework

React

RendererSet

Material

Additional context

No response

luiz290788 avatar Feb 16 '23 19:02 luiz290788

Hi @luiz290788, as discussed in the forum, this is not a use case which we currently support.

We currently resolve the rule condition scopes against the sub-schema of the array element and also only validate against the array/object data. Conceptually it's not possible to refer to the parent/root element as the JSON Schema based pointers are not expressive enough to then refer to the "current" array element again without introducing some special enhancement.

A straightforward enhancement could be to offer something like parentCondition and/or rootCondition. While this would not solve all use cases it would solve many of them and would be easy to implement.

sdirix avatar Feb 20 '23 08:02 sdirix

Hi @luiz290788, as discussed in the forum, this is not a use case which we currently support.

We currently resolve the rule condition scopes against the sub-schema of the array element and also only validate against the array/object data. Conceptually it's not possible to refer to the parent/root element as the JSON Schema based pointers are not expressive enough to then refer to the "current" array element again without introducing some special enhancement.

A straightforward enhancement could be to offer something like parentCondition and/or rootCondition. While this would not solve all use cases it would solve many of them and would be easy to implement.

Hi, i need this enhancement for some features i would implement for my project. Can you tell me if the resolution for this issue in the roadmap? Do you have some suggestions about an alternative approach to use? i see that the ui-schema can rely on "options" object, do you believe that a combination of custom options and custom middleware is the right way to implement a custom feature without using core features?

Thanks in advance.

Luigi

muten84 avatar Mar 28 '24 16:03 muten84