Array of strings - strings defined by other JSON fields

Assuming I have a JSON that looks like this:

{
   "name" : [
       { "First": "Bob", "Last": "Jones" },
       { "First": "Sally", "Last":"Smith" }
  ],
   "FirstNames" : []
}

I just used jsonforms to populate the name array.

Now, I want jsonforms to offer me a list of name[].FirstName when populating the FirstNames array.

I can easily create the array of first names ( let fn = names.map((n)=> return n.First) ), do I use a jsonforms custom renderer to supply those options when populating FirstNames?

Hi @kris,

JSON Schema is not expressive enough to formulate your requirements. The way to go is to use a custom renderer FirstNames which looks up the data for name in the form and only offers the options you’d like to see.

You can even mostly reuse the existing enum renderers here but just hand them over your custom options.

@sdirix

Thanks Stefan.

It looks like MaterialArrayControlRenderer isn’t exposed as “Unwrapped” (enum doesn’t work since I need people to select more than one)

Do you have any examples of how to use MaterialArrayControlRenderer as a custom renderer?

I think my first step in figuring this out is to duplicate the existing renderer as a custom renderer with my own tester. I can’t seem to get that far yet :slight_smile:

Second step would be to figure out how to pass in the existing data/state.

Any additional pointers?
Thanks!

Hi @kris,

The MaterialArrayControlRenderer is way too overkill for this use case. You will have a better experience when implementing a new custom renderer. For selecting multiple elements from an array we have the currently undocumented MaterialEnumArrayRenderer. You can use this code as a guideline for your renderer.

An example to trigger this renderer is here.