@tisuchi im aware of similar validation and im using it right now. This seems too broad though. It doesnt validate if certain group belogs to given form nor the value of the field. The only solution that comes to my mind is that since i have the form.id i can validate it for existence then load its groups and fields of each group and wite some custom complicated validation logic that validates if data from frontend matches the relations, field types etc. It seems very dirty though.
Maybe i did not include it in my post but the thing is i want to validate structure itself too, say the JSON in 1st post passes the validation but consider the following examples:
example 1: group not related / field not related
{
"form": {
"id": 17,
"groups": [
{
"name": "account_name",
"fields": [
{
"name": "account_name",
"value": 1234
}
]
},
{
"name": "service",
"fields": [
{
"name": "service",
"value": "courier"
}
]
},
{
"name": "sizing",
"fields": [
{
"name": "small",
"value": 1
},
{
"name": "unrelated_field",
"value": 1
}
]
},
{
"name": "posh_services",
"fields": [
{
"name": "super_fast",
"value": true
},
{
"name": "gilded_box",
"value": true
}
]
},
{
"name": "unrelated_group",
"fields": [
{
"name": "abc",
"value": "def"
}
]
}
]
}
}
in this example i'd need to fail validation since theres one unrelated_group and one of the fields in group "sizing" has unrelated field. I need this to be validated against current state of form and it's relations in DB.
example 2: wrong type of value for field
{
"form": {
"id": 17,
"groups": [
{
"name": "account_name",
"fields": [
{
"name": "account_name",
"value": 1234
}
]
},
{
"name": "service",
"fields": [
{
"name": "service",
"value": "courier"
}
]
},
{
"name": "sizing",
"fields": [
{
"name": "small",
"value": 1
}
]
},
{
"name": "posh_services",
"fields": [
{
"name": "super_fast",
"value": true
},
{
"name": "gilded_box",
"value": "maybe"
}
]
}
]
}
}
in this example field with name "gilded_box" has wrong value type. Again I have got the info on field value type stored in DB but it all seems convoluted and i feel like im missing some easy way to achieve this kind of validation