Skip to content

oneOf fields do not preselect with loaded data #1273

@johnmorrell

Description

@johnmorrell

Describe the bug
When a schema with a oneOf property is rendered and loaded with a data set. The oneOf field always preselects the first items and may render data from the an incorrect option.

To Reproduce

UISchema:

{
   "type":"object",
   "properties":{
      "quantity":{
         "oneOf":[
            {
               "$ref":"#/definitions/unrangedQuantity"
            },
            {
               "$ref":"#/definitions/rangedQuantity"
            }
         ]
      }
   },
   "definitions":{
      "unrangedQuantity":{
         "title":"Value",
         "type":"object",
         "properties":{
            "value":{
               "type":"number"
            },
            "unit":{
               "type":"string"
            }
         },
         "required":[
            "value",
            "unit"
         ]
      },
      "rangedQuantity":{
         "title":"Range",
         "type":"object",
         "properties":{
            "valueLow":{
               "type":"number"
            },
            "valueHigh":{
               "type":"number"
            },
            "unit":{
               "type":"string"
            }
         },
         "required":[
            "valueLow",
            "valueHigh",
            "unit"
         ]
      }
   }
}

Data:

{
   "quantity":{
      "valueLow":1,
      "valueHigh":10,
      "unit":"kg"
   }
}

Screenshot:

screenshot 2019-02-25 at 10 34 30

Expected behavior
The correct field is selected and populated. This may be potentially quite complicated due to the recursive nature. Ideally the data could be validated against each of the oneOf items and populate the first it validates against.

Browser (please complete the following information):

  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Used Setup (please complete the following information):

  • Framework: React
  • RendererSet: Material

Additional context

  • JSONForms: 2.2.1-alpha.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions