Full JSON Object Structure
...
"validators": {
"validation": [
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "{{JsonkeyName}}",
"value": "{{JsonValueToCheckFor}}"
}
}
]
},
...
This validator is used to validation against field values that have objects as their values.
*jsonKeyValueIsEqualTo - Json Key Must be the defined value*
An example is the Data Set Drop down (Non-paginated for example).
An example of value set on the field is this when Rwanda is selected:
{ "id": "2396e507-561f-4ce6-8410-59f6b11fad44", "version": 0, "createdDate": "2023-06-08T15:27:13.946518", "createdById": "647ce246-f41b-4de6-a88b-632525e463b1", "lastModifiedDate": "2023-06-08T15:27:13.946518", "lastModifiedById": "647ce246-f41b-4de6-a88b-632525e463b1", "deleted": false, "datasetId": "dc8ac5fe-6daf-4152-9f91-08887d3e8fce", "label": "Rwanda", "value": "RWANDA", "details": { "country": "Rwanda" } }
For example, we can use this to set an error when we want a key's value in this JSON to be a desired value.
If we only want the value of RWANDA , we can pass define the json key value , and and the accepted value of RWANDA .
"validators": {
"validation": [
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "value",
"value": "RW"
}
}
]
},
"validation": {
"messages": {
"jsonKeyValueIsEqualTo": "You can not select Rwanda "
}
},
Please remember to set the validation message too.
Also for the case of RWANDA in the country datasets, you might need to set multiple validations as we have multiple RWANDA options with values like RW, RWA, RWANDA.
"validators": {
"validation": [
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "value",
"value": "RW"
}
},
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "value",
"value": "RWANDA"
}
},
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "value",
"value": "RWA"
}
}
]
},
You might also settle to use the label as value instead.
"validators": {
"validation": [
{
"name": "jsonKeyValueIsEqualTo",
"options": {
"key": "label",
"value": "Rwanda"
}
}
]
},
Possible Options
See jsonKeyValueIsEqualTo in the maintained Validators reference.