Full JSON Object Structure
...
"validators": {
"validation": [
\ {
"name": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "{{JsonkeyName}}",
"value": "{{JsonValueToCheckFor}}"
}
}
]
},
...
This validator is used to validation against field values that have objects as their values.
*jsonKeyValueIsNotEqualTo - Json Key Must NOT 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 do not want a key's value in this JSON to not be a desired value.
If we do not want the value of RWANDA , we can pass define the json key value , and an unaccepted value of RWANDA .
"validators": {
"validation": [
{
"name": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "value",
"value": "RW"
}
}
]
},
"validation": {
"messages": {
"jsonKeyValueIsNotEqualTo": "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": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "value",
"value": "RW"
}
},
{
"name": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "value",
"value": "RWANDA"
}
},
{
"name": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "value",
"value": "RWA"
}
}
]
},
You might also settle to use the label as value instead.
"validators": {
"validation": [
{
"name": "jsonKeyValueIsNotEqualTo",
"options": {
"key": "label",
"value": "Rwanda"
}
}
]
},
Possible Options
See jsonKeyValueIsNotEqualTo in the maintained Validators reference.