Closed
Description
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