Symfony2 - Validation not working for embedded Form Type

后端 未结 8 1414
北海茫月
北海茫月 2020-12-07 12:59

I have a form that combines two entities (User and Profile).

Validation seems to work on the first part of the form that comes form the User Entity and is the basis

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 13:35

    According to form type documentation you can also use Valid constraint instead of cascade_validation option.

    $builder->add('children', 'collection', array(
        'type'        => new ChildType(),
        'constraints' => array(new Valid()),
    ));
    

    Example from the owner entity:

    /**
     * @var Collection
     *
     * @ORM\OneToMany(targetEntity="Child", ...)
     * @Assert\Valid()
     */
    private $children
    

提交回复
热议问题