Hi! I will be very grateful for your help
I’ve read topic.
I realized that I can create only one if/then/else condition to set required fields by condition, but I need several unrelated ones.
This is my example scheme.json
{
"type": "object",
"properties": {
"realEstateMarket": {
"title": "Real Estate Market",
"type": "string",
"enum": ["primary", "secondary"],
"default": "primary"
},
"primaryMarket": {
"type": "object",
"properties": {
"housingComplexClass": {
"type": "string",
"enum": ["premium", "econom", "comfort", "business"]
},
"comissioning": {
"type": "string",
"format": "year",
"stringLength": 4
}
}
},
"realEstateCategory": {
"type": "string",
"title": "Категорія нерухомості",
"enum": ["housing_stock", "commerce", "land", "garages"]
},
"plotOfLand": {
"type": "string",
"title": "Ділянка, соток",
"customRender": "numeric",
"deximal": true
},
},
"if": {
"properties": {
"realEstateMarket": {
"const": "primary"
}
}
},
"then": {
"properties": {
"primaryMarket": {
"required": ["housingComplexClass", "comissioning"]
}
}
},
"else": {
"required": ["yearOfConstruction"]
}
}
I need add more such conditions, for example:
if property “realEstateCategory” === “land”, then property “plotOfLand” must be required. It’s very important for our project.
I changed the condition if/then/else/ in my schema to allOf, to set several if/then/else conditions
"allOf": [
{
"if": {
"properties": {
"realEstateMarket": {
"const": "primary"
}
}
},
"then": {
"properties": {
"primaryMarket": {
"required": ["housingComplexClass", "comissioning"]
}
}
},
"else": {
"required": ["yearOfConstruction"]
}
},
{
"if": {
"properties": {
"realEstateCategory": {
"const": "land"
}
}
},
"then": {
"required": ["plotOfLand"]
}
}
]
And it works, how I expect !!!
BUT typescript is very angry for me ))) I have no idea how to get around this problem