I have a schema that has a conditional subschema called ‘config’ based on a dataset ‘type’. Following advice from other posts on the forum I have restructured if/then stanzas in my schema to a oneOf but
First, similar to described here. However this gives a ‘no applicable renderer found’ even if I explicitly specify a oneOfControl variant for the tester. The issue is not the renderer as I am using a variant of vue-vanilla renderers that works in a subsequent example.
{
"type": "Control",
"scope": "#/oneOf",
"options": {
"readonly": false,
"variant": "oneOfControl",
},
},
Second, I followed the second suggestion of using UISchema rules. I have the following under the scope of #/properties:
"type": {
"title": "Dataset type",
"enum": [ "DATASET_TYPE1", "DATASET_TYPE2", "DATASET_TYPE3", "DATASET_TYPE4", "DATASET_TYPE5"]
},
"config": {
"oneOf": [
{
"$ref": "#/$defs/dataset1"
},
{
"$ref": "#/$defs/dataset2"
},
{
"$ref": "#/$defs/dataset3"
},
{
"$ref": "#/$defs/dataset4"
},
{
"$ref": "#/$defs/dataset5"
}
]
}
And a UISchema to conditionally display
{
"type": "Group",
"elements": [
{
"type": "Control",
"label": "Dataset 1 Config",
"scope": "#/properties/config/oneOf[0]",
"rule": {
"effect": "SHOW",
"condition": {
"scope": "#/properties/type",
"schema": {
"const": "DATASET_TYPE1"
}
}
}
}
]
}
but get a syntax error
SyntaxError: Identifier 'schema1' has already been declared
Finally, the closest to my result is emulating the vuetify oneOf-tab example by nesting the oneOf under an object property like so.
"type": {
"oneOf": [
{
"title": "DATASET_1",
"type": "object",
"properties": {
"type": {
"const": "DATASET_1"
},
"config": {
"$ref": "#/$defs/dataset1"
}
}
},
]}
And this renders as expected but as it is a nested property, no longer binds with form data. Based on these
- Is there a correct way to declare a oneOf control in the UISchema (that is not nested under a property)?
- Am I missing a ‘correct’ syntax for displaying an indexed item in the oneOf?
- If I must nest the oneOf, is there a way to specify what data to bind to (e.g., the “type” and “config” properties under “type” should bind to root level data)?