Skip to content

Commit f45f0d0

Browse files
committed
[Form] Preventing validation of children if parent with Valid constraint has no validation groups
1 parent 42c08b8 commit f45f0d0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function validate($form, Constraint $formConstraint)
4444
if ($form->isSubmitted() && $form->isSynchronized()) {
4545
// Validate the form data only if transformation succeeded
4646
$groups = self::getValidationGroups($form);
47+
48+
if (!$groups) {
49+
return;
50+
}
51+
4752
$data = $form->getData();
4853

4954
// Validate the data against its own constraints

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,28 @@ public function testDontValidateConstraintsIfNoValidationGroups()
220220
$this->assertNoViolation();
221221
}
222222

223+
public function testDontValidateChildConstraintsIfCallableNoValidationGroups()
224+
{
225+
$formOptions = [
226+
'constraints' => [new Valid()],
227+
'validation_groups' => [],
228+
];
229+
$form = $this->getBuilder('name', null, $formOptions)
230+
->setCompound(true)
231+
->setDataMapper(new PropertyPathMapper())
232+
->getForm();
233+
$childOptions = ['constraints' => [new NotBlank()]];
234+
$child = $this->getCompoundForm(new \stdClass(), $childOptions);
235+
$form->add($child);
236+
$form->submit([]);
237+
238+
$this->expectNoValidate();
239+
240+
$this->validator->validate($form, new Form());
241+
242+
$this->assertNoViolation();
243+
}
244+
223245
public function testDontValidateIfNotSynchronized()
224246
{
225247
$object = new \stdClass();

0 commit comments

Comments
 (0)