Skip to content

Assert\Valid not working as expected with Embedded Forms and validation groups #9650

@guillaumesmo

Description

@guillaumesmo

The Assert\Valid is not taken into account and the form is just considered valid, even if the constraints are not met. The issue can be reproduced by taking the example over here :
http://symfony.com/doc/current/book/forms.html#embedding-a-single-object

  • Add any constraint to Entity\Category with: groups={"validationgroup"}
  • Change @Assert\Type(...) in Entity\Task to @Assert\Valid
  • Add 'validation_groups' => array('validationgroup') to Form\Type\CategoryType in $resolver->setDefaults
  • Remove 'cascade_validation' => true, from Form/Type/TaskType. As we use Assert\Valid, this should not be necessary, or am I wrong?
  • Create a controller:
class TestController extends Controller
{
    public function indexAction()
    {
        $form = $this->createForm(new TaskType(), new Task());
        $form->add('save', 'submit');

        $form->handleRequest($this->getRequest());

        if($form->isValid()){
            echo '<p>the form is valid...</p>';
        }

        return $this->render('AcmeDemoBundle:Test:taskform.html.twig', array(
            'form' => $form->createView()
        ));
    }
}
  • and twig template :
<h3>Add task</h3>
{{ form(form) }}

I can provide you this bundle, zipped, if you want. I have also found that (by placing a debug closure in validation_groups) the validation_groups is read by the validator but it doesn't seem to be used.

Tested with version 2.3.7

capture

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy