eclipsesource / eclipsesource/jsonforms

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

Open
#1,634 2 comments 2 reactions 0 assignees View on GitHub
feature material react
Dominant language
TypeScript
Stars
2.7k
Forks
424
Avg merge
17d 8h
Merged PRs (30d)
1

Description

**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"
}
]
};
```
2. Click on Address and the default Info Type is address
3. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.