Skip to content

Commit

Permalink
properly cascade validation to child forms
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 3, 2020
1 parent 3519647 commit babe8ce
Showing 1 changed file with 2 additions and 5 deletions.
Expand Up @@ -72,7 +72,6 @@ public function validate($form, Constraint $formConstraint)
if ($groups instanceof GroupSequence) {
// Validate the data, the form AND nested fields in sequence
$violationsCount = $this->context->getViolations()->count();
$fieldPropertyPath = \is_object($data) ? 'children[%s]' : 'children%s';

foreach ($groups->groups as $group) {
if ($validateDataGraph) {
Expand All @@ -91,7 +90,7 @@ public function validate($form, Constraint $formConstraint)
// in different steps without breaking early enough
$this->resolvedGroups[$field] = (array) $group;
$fieldFormConstraint = new Form();
$validator->atPath(sprintf($fieldPropertyPath, $field->getPropertyPath()))->validate($field, $fieldFormConstraint);
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint);
}
}

Expand All @@ -100,8 +99,6 @@ public function validate($form, Constraint $formConstraint)
}
}
} else {
$fieldPropertyPath = \is_object($data) ? 'children[%s]' : 'children%s';

if ($validateDataGraph) {
$validator->atPath('data')->validate($data, null, $groups);
}
Expand Down Expand Up @@ -132,7 +129,7 @@ public function validate($form, Constraint $formConstraint)
if ($field->isSubmitted()) {
$this->resolvedGroups[$field] = $groups;
$fieldFormConstraint = new Form();
$validator->atPath(sprintf($fieldPropertyPath, $field->getPropertyPath()))->validate($field, $fieldFormConstraint);
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint);
}
}
}
Expand Down

0 comments on commit babe8ce

Please sign in to comment.