Hi,
I am trying to render images dynamically using a custom renderer.
If I use "type": "Group" in UI Schema and "oneOf" in Schema, when I switch the tabs and go to the next form, the data in the previous form is cleared (as can be seen in the image below), which is what I need, but the problem is that I cannot render different images for different tabs because in the UI Schema, I can have only one image for the whole group.
Is there a solution so that I can render one image if the tab “DESCRIPTION” is active, and render another image if the tab “DEPARTMENT” is active?
I checked the custom react hook
useJsonForms(), but it does not provide a state for the active tab. Does JsonForms provide other custom hooks or is there a way that I can keep track of the active tab?
// UI Schema
{
"type": "VerticalLayout",
"elements": [
{
"type": "Group",
"label": "Person",
"elements": [
{
"type": "Control",
"scope": "#/properties/person"
}
]
}
]
}
// Schema
{
"type": "object",
"properties": {
"person": {
"oneOf": [
{
"oneOf": [
{
"$ref": "#/definitions/description",
"title": "description"
},
{
"$ref": "#/definitions/department",
"title": "department"
}
],
"title": "job"
},
{
"oneOf": [
{
"$ref": "#/definitions/name",
"title": "name"
}
],
"title": "Info"
}
]
}
},
"definitions": {
"description": {
"type": "object",
"properties": {
"description": {
"type": "string"
}
}
},
"department": {
"type": "object",
"properties": {
"department": {
"type": "string"
}
}
},
"name": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
I tried another solution as well. Instead of using "type": "Group", I used "type": "Categorization",. This way, I can render different images for different tabs, but the problem is that after changing the tab, the data from the previous form persists and makes problem for form submission.
// UI Schema
{
"type": "Categorization",
"elements": [
{
"type": "Category",
"label": "Description",
"elements": [
{
"type": "Control",
"scope": "#/properties/description/properties/description"
}
]
},
{
"type": "Category",
"label": "Department",
"elements": [
{
"type": "Control",
"scope": "#/properties/department/properties/department"
}
]
},
{
"type": "Category",
"label": "Name",
"elements": [
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/firstName"
},
{
"type": "Control",
"scope": "#/properties/secondName"
}
]
},
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/birthDate"
},
{
"type": "Control",
"scope": "#/properties/nationality"
}
]
}
]
}
]
}
// Schema
{
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"secondName": {
"type": "string"
},
"birthDate": {
"type": "string",
"format": "date"
},
"nationality": {
"type": "string",
"enum": [
"IT",
"JP",
"US",
"Other"
]
},
"description": {
"type": "object",
"properties": {
"description": {
"type": "string"
}
}
},
"department": {
"type": "object",
"properties": {
"department": {
"type": "string"
}
}
}
}
}
I need a dynamic solution that works with similar forms but with different input fields, so I cannot hardcode the field names in the custom renderer.

