I am using:
“@jsonforms/core”: “^2.4.0”,
“@jsonforms/material-renderers”: “^2.4.0”,
“@jsonforms/react”: “^2.4.0”.
Based on the oneOf examples, I wanted to get the title from one of theelements in the oneOf arrays (either address or socials) to also be populated in the generated json depending on what the user selects.
You can see my implementation here, admiring-fermi-wy57n - CodeSandbox. This is the output I wanted to receive if the user select “address” and enter the info:
{
"name": "Tom",
"infoType": "address",
"info": {
"infoType": "address", // or this
"street_address": "110 Main Street",
"city": "Los Angeles",
"state": "CA"
}
}
or if the user selects “socials” then:
{
"name": "Tom",
"infoType": "socials",
"info": {
"infoType": "socials", // or this
"name": "Tom"
"twitter": "@tom",
"mail": "tom@tom.com"
}
}
I was able to use ajv defaults to populate the default, but if the user clicks another selection the default does not update. Do you have any other recommendations on how I can achieve this? The infoType key does not necessarily have to be nested in the info object it can also be on the same level as the info key.
Hi @avath(avath) ,
just for clarification you want to have defaults for the info object based on the selection of the infoType? And switching the infoType does not repopulate the default values?
I am not sure if using defaults is the right way to do this, but ultimately, I want to be able to capture the title value (in this case “address” or “socials”) from the “oneOf” when it is selected.
I am not sure if I follow. Currently, the form is listening to the data on change and you can see the json data I get populated on the left. The only field I am missing there is a key “infoType” with the value of “socials”. No Matter which button I click the default remains to be “address”.
ok, sorry mu fault, I misunderstood you.
Ok so the infotype itself is not changing if you switch between address and socials? sorry I thought it worked when I tried it out, but it doesn’t as I can now see.
I would say it is a bug and should be fixed in jsonforms. It looks like the wrong schema is used.
Could you open a bug for this please?