Skip to content

Commit

Permalink
[Form] Preventing validation of children if parent with Valid constra…
Browse files Browse the repository at this point in the history
…int has no validation groups
  • Loading branch information
maryo committed Mar 19, 2019
1 parent 42c08b8 commit f45f0d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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();
Expand Down

0 comments on commit f45f0d0

Please sign in to comment.