diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index 7922bcc74c87..14adf123ec41 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -44,6 +44,11 @@ public function validate($form, Constraint $formConstraint) if ($form->isSubmitted() && $form->isSynchronized()) { // Validate the form data only if transformation succeeded $groups = self::getValidationGroups($form); + + if (!$groups) { + return; + } + $data = $form->getData(); // Validate the data against its own constraints diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index 7581f7698c12..4ab56f555a90 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -220,6 +220,28 @@ public function testDontValidateConstraintsIfNoValidationGroups() $this->assertNoViolation(); } + public function testDontValidateChildConstraintsIfCallableNoValidationGroups() + { + $formOptions = [ + 'constraints' => [new Valid()], + 'validation_groups' => [], + ]; + $form = $this->getBuilder('name', null, $formOptions) + ->setCompound(true) + ->setDataMapper(new PropertyPathMapper()) + ->getForm(); + $childOptions = ['constraints' => [new NotBlank()]]; + $child = $this->getCompoundForm(new \stdClass(), $childOptions); + $form->add($child); + $form->submit([]); + + $this->expectNoValidate(); + + $this->validator->validate($form, new Form()); + + $this->assertNoViolation(); + } + public function testDontValidateIfNotSynchronized() { $object = new \stdClass();