elementLabelProp displays const instead of title of oneOfs (MaterialRenderer)

Hi @rwoerzbe,

Sadly the elementLabelProp concept is not generic enough to achieve the desired behavior as it’s designed to directly access the actual data. To adapt this in JSON Forms we must come up with a more powerful concept.

If you don’t care about the structure of your data or a willing to add transformers, then you could adapt your JSON Schema to:

  • store the title alongside the value in the data. In that case elementLabelProp could refer to the stored title in the data, e.g. oneOf: [ { title: 'ABC', const: { title: 'ABC', value: 'A' }} ]. Obviously that is a rather dirty hack
  • Only use the title in your JSON Schema, e.g. enum: ["A is the...", "B is the..."]. Then transform the stored titles into their actual values as a step inbetween JSON Forms and your application.

The clean solution is to fix this with a custom renderer. In this case you would need to copy the MaterialArrayLayout and write and use a new binding for the ExpandPanelRenderer in which you can add the behavior you like to see. The newly wrapped CustomExpandPanelRenderer can then be used in your MaterialArrayLayout. Then register this as a custom renderer with a higher priority as the existing MaterialArrayLayout and your’e done.

Now taking a step back I would like to actually recommend instead is just doing the same solution as in the linked topic. There is no reason to not show these two attributes directly within a table. This not only renders a cleaner UI as the expandable sections are still overkill for only two attributes, it also avoids the elementLabelProp issues. All you need to do is to adapt the tester in the linked topic to also recognize the structure with a shallow object and multiple oneOfs as properties.

1 Like