There is a class Item
. It has an attribute type
, that can be a
, b
, or c
. For all the types there is a common minimal set of attributes / input fields: type
and other ones. Every type has some further attributes:
default set of the common fields
type
...
additional fields in case of type=a
foo
additional fields in case of type=b
bar
baz
additional fields in case of type=c
bar
baz
buz
Furthermore the validation rules for bar
and bar
are slightly different for the cases type=b
and type=c
.
How to set up the validation in a ZF2/Apigilty application depending on the value of a field (or multiple fields)? For this concrete case: How to set up the validation depending on the type
?
UPDATE
The attribute type
is an independent one. That means -- it should not become invalid, if the set of the additional fields (foo
, bar
etc.) doesn't match to it. (It's required
and gets validated agains an array of the allowed values, that's it.)
So, it should work in the opposite direction:
IF (type == 'a') {
proper "required" and validation rules the additional fields
} ELSEIF (type == 'b') {
proper "required" and validation rules the additional fields
} ELSEIF (type == 'c') {
proper "required" and validation rules the additional fields
}