In Symfony 3, its not allowed to use cascade_validation
anymore. So you have to make an Assert for the types. But it doesn't work, the form is valid even when a field is BLANK but the Assert said NOtBlank. I have a class Participants and I want to check the Adults ArrayCollection when checking my participant Model.
//Participant Model
/**
* @var ArrayCollection
* @Assert\All({
* @Assert\Type(type="My\WebsiteBundle\Model\Adult"),
* })
*/
protected $adults;
//Adult Model
class Adult
{
/**
* @var string
*
* @Assert\NotBlank()
*/
protected $salutation;
/**
* @var string
*
* @Assert\NotBlank()
*/
protected $firstname;
/**
* @var string
*
* @Assert\NotBlank()
*/
protected $lastname;
You should use the Valid assetion as described here http://symfony.com/doc/current/reference/constraints/Valid.html in the doc
As example:
/**
* @var ArrayCollection
*
* @Assert\All({
* @Assert\Type(type="My\WebsiteBundle\Model\Adult"),
* })
* @Assert\Valid
*/
protected $adults;
Hope this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With