Skip to content

Default value associated to oneOf element does not change with user selection #1634

Open
@portatlas

Description

@portatlas

Describe the bug
The default values associated with each "oneOf" selections does not get updated when a user picks another "oneOf" element. In the example below there is a oneOf selection with two available options 1.) Address (default is "address") and 2.) Socials (default is socials). When the user selects Socials the default is still address.

To Reproduce

  1. Create a json form with the following schema and uischema.
const schema = {
  $schema: "http://json-schema.org/draft-07/schema#",
  definitions: {
    address: {
      type: "object",
      properties: {
        infoType: { type: "string", default: "address" },
        street_address: { type: "string" },
        city: { type: "string" },
        state: { type: "string" }
      },
      required: ["street_address", "city", "state"]
    },
    socials: {
      type: "object",
      properties: {
        infoType: { type: "string", default: "social" },
        twitter: { type: "string" },
        mail: { type: "string" }
      },
      required: ["name", "mail"]
    },
    userInfoType: {
      type: "string",
      enum: ["address", "socials"]
    }
  },
  type: "object",
  properties: {
    name: { type: "string" },
    info: {
      oneOf: [
        {
          $ref: "#/definitions/address",
          title: "Address"
        },
        {
          $ref: "#/definitions/socials",
          title: "Socials"
        }
      ]
    }
  }
};

export const uischema = {
  type: "VerticalLayout",
  elements: [
    {
      type: "Control",
      scope: "#/properties/name"
    },
    {
      type: "Control",
      scope: "#/properties/info"
    }
  ]
};
  1. Click on Address and the default Info Type is address
  2. Click on Socials and the default Info Type is still "address" and does not change

Expected behavior
The expected behavior, is that when a user selects a oneOf option then the associated default option for that oneOf should be updated. In this case, when a user selects "Socials" then the default InfoType should be "socials".

Screenshots
https://codesandbox.io/s/admiring-fermi-wy57n?from-embed=&file=/src/App.tsx:889-2099

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
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions