[Form] Preventing validation of children if parent with Valid constraint has no validation groups
This commit is contained in:
parent
42c08b8966
commit
f45f0d03fc
|
@ -44,6 +44,11 @@ class FormValidator extends ConstraintValidator
|
|||
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
|
||||
|
|
|
@ -220,6 +220,28 @@ class FormValidatorTest extends ConstraintValidatorTestCase
|
|||
$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();
|
||||
|
|
Reference in New Issue