Reputation: 335
How to make the validation range dependent on the validation group?
For example:
We have a variable, that is assigned to three groups.
When we validate group A, the variable x should take a value between 0 until 10. When we validate group B, the variable x should be blank.
How could we define these dependencies in the annotations?
Thank you!
Upvotes: 0
Views: 124
Reputation: 4355
Validation groups are designed to solve such problems. In your case, you should just add validation constraint annotations and set up groups for each constraint.
/**
* @var float
*
* @ORM\Column(name="value", type="decimal", scale=2, nullable=true)
*
* @Assert\Range(min="0", max="10", groups={"groupA"})
* @Assert\Blank(groups={"groupB"})
* @Assert\Range(min="20", max="50", groups={"groupC"})
*/
private $value;
Upvotes: 2