Render a list and be able to select an item from that list

Hi,

My question is, is there a way to render an array of objects (or strings), and be able to do select on them? I saw that enums are ok for selecting, but you must predefine values, and i saw arrays, Array | JSON Forms , but I don’t know is it possible to select an item from an array.

Thanks!

[original thread by Stefan Čović]

Hi @stefan-covic! You can specify arbitrary values when you use a oneOf enum-like construction. They are specified like this:

"oneOf": [
  {
    "title": "Option1",
    "const": // whatever value you like to have 
   },
   {
    "title": "Option2",
    "const": // whatever value you like to have 
    }
]

Example:

{
  "type": "object",
  "properties": {
    "name": {
      "oneOf": [
        {
          "const": {
            "foo": "bar",
            "bar": "foo"
          },
          "title": "Option1"
        },
        {
          "const": {
            "foo2": "bar2",
            "bar2": "foo2"
          },
          "title": "Option2"
        }
      ]
    }
  }
}

If you like to being able to define editable and selectable objects within one control then you will need to write a custom renderer.

[Stefan Čović]

Thank you for the answer! But is it possible to set ‘oneOf’ array dynamically, outside of a schema, through the data?

You could either

  • exchange the schema whenever you have new values for the oneOf

  • use a custom renderer which renders a dropdown with whatever values you like. In that case you don’t need the oneOf at all

[Stefan Čović]

Ok, thank you very much, appreciate it!