I’m having trouble with getting a SHOW rule to work when using it against an array of objects, where there is a list of values that should trigger the form elements to be shown.
I’m using react JSONForms, v3.1.0 with react v18.2.0.
It’s always showing the form elements, no matter what the array values are, even if the array is empty. I’ve tried many different variations with the rule’s condition, but I have no idea if I’m even getting close to a correct answer since I’m not successfully finding examples that are using arrays of objects.
This is a simplified schema. The issue I’m having troubles with, on the rule SHOW
starts on line 40 with the HorizontalLayout control. This element should be shown if an animals
array item has an ontology_id
value of : “cats”, “kittens”, or “felines”.
{
"properties": {
"animals": {
"items": {
"properties": {
"ontology_id": { "type": "string" },
"ontology_label": { "type": "string" },
"text": { "type": "string" }
},
"type": "object"
},
"type": "array"
},
"cats": {
"type": "object",
"properties": {
"name": { "type": "string" },
"warrior": { "type": "boolean" },
"clan": { "type": "string" },
"kittypet": { "type": "boolean" },
"twoleg_friend": { "type": "string" }
}
}
}
}
And the schema UI:
{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"label": "Animals",
"scope": "#/properties/animals/",
"options": {
"elementLabelProp": "text",
"detail": {
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"label": "Animal",
"scope": "#/properties/text"
},
{
"type": "autocomplete",
"label": "Animal ontology label",
"scope": "#/properties/ontology_label",
"options": {
"optionName": "name",
"listurl": "/edit/list/animals.json",
"updateOtherFields": [
{ "optionName": "name", "field": "text" },
{ "optionName": "id", "field": "ontology_id" }
]
}
},
{
"type": "Control",
"label": "Animal ontology ID",
"scope": "#/properties/ontology_id"
}
]
}
}
},
{
"type": "HorizontalLayout",
"rule": {
"effect": "SHOW",
"condition": {
"scope": "#/properties/animals/items/properties/ontology_id",
"type": "LEAF",
"expectedValue": [
"cats",
"kittens",
"felines"
]
}
},
"elements": [
{
"type": "Fieldset",
"label": "Warrior cat",
"elements": [
{
"type": "Control", "label": "Cat name",
"scope": "#/properties/cats/properties/name"
}, {
"type": "Control", "label": "Warrior?",
"scope": "#/properties/cats/properties/warrior"
}, {
"type": "Control", "label": "Clan",
"scope": "#/properties/cats/properties/clan"
}, {
"type": "Control", "label": "Was a kittypet?",
"scope": "#/properties/cats/properties/kittypet"
}, {
"type": "Control", "label": "twoleg owner",
"scope": "#/properties/cats/properties/twoleg"
}
]
}
]
}
]
}
I should note that the autocomplete
control is based upon MUI material’s autocomplete, but is able to update multiple fields from the url’s selected object. The Fieldset
control just wraps its children in a fieldset html element, with an optional label.
Is there anything else you would need to see? I’m not sure how to setup a working example to show how this is/isn’t working. Is there a doc that shows how to setup a react jsonforms example?
Thanks greatly for your time and help!