[Nanda]
Hi,
I am trying to implement condition based required validation. But its not working.
I have dropdown with values circle, square and rectangle.
If I select circle then “radius” property is required.
If I select square then “height” property is required.
If I select rectangle then “height” and “Width” properties are required.
But none of the validations are working. Am I miss anything?
Schema:
{
"type": "object",
"properties": {
"shapeType": {
"type": "string",
"enum": [
"",
"square",
"circle",
"rectangle"
]
},
"shapeProperties": {
"properties": {
"radius": {
"type": "number"
},
"height": {
"type": "number"
},
"width": {
"type": "number"
}
},
"allOf":[
{
"if": {
"properties": {
"shapeType": {
"const": "square"
}
},
"required": [
"shapeType",
"shapeProperties"
]
},
"then": {
"required": [
"height"
]
}
},
{
"if": {
"properties": {
"shapeType": {
"const": "circle"
}
},
"required": [
"shapeType",
"shapeProperties"
]
},
"then": {
"required": [
"radius"
]
}
},
{
"if": {
"properties": {
"shapeType": {
"const": "rectangle"
}
},
"required": [
"shapeType",
"shapeProperties"
]
},
"then": {
"required": [
"height",
"width"
]
}
}
]
}
},
"if": {
"properties": {
"shapeType": {
"const": "square"
}
},
"required": [
"shapeType"
]
},
"then": {
"required": [
"shapeProperties"
]
}
}
UI Schema
{
"type": "VerticalLayout",
"elements": [
{
"type": "Group",
"label": "Shape Type",
"elements": [
{
"type": "Control",
"label": "Shape Type",
"scope": "#/properties/shapeType"
}
]
},
{
"type": "Group",
"label": "Shape Properties",
"elements": [
{
"type": "Control",
"label": "Radius",
"example": "Ex: 5467234786",
"scope": "#/properties/shapeProperties/properties/radius"
},
{
"type": "Control",
"label": "Height",
"scope": "#/properties/shapeProperties/properties/height"
},
{
"type": "Control",
"label": "Width",
"scope": "#/properties/shapeProperties/properties/width"
}
],
"rule": {
"effect": "SHOW",
"condition": {
"scope": "#/properties/shapeType",
"schema": {
"enum": [
"square",
"circle",
"rectangle"
]
}
}
}
}
]
}