Skip to content

Commit

Permalink
Fix nested validation #13
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Nov 2, 2019
1 parent 38454ec commit 746fae0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Extension/Validation/ValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,29 @@ public function validateRules(FormEvent $event)
* @param array $rules
* @return array
*/
protected function findRules(FormInterface $parent, $rules = [])
protected function findRules(FormInterface $parent, $rules = [], $parentName = null)
{
foreach ($parent->all() as $form) {
$config = $form->getConfig();
$name = $form->getName();
$innerType = $form->getConfig()->getType()->getInnerType();

if ($config->hasOption('rules')) {
if ($innerType instanceof CollectionType) {
$name .= '.*';
}

if (! $parent->isRoot()) {
if ($parentName !== null) {
$name = $parentName . '.' . $name;
} elseif (! $parent->isRoot()) {
$name = $parent->getName() . '.' . $name;
}

$rules[$name] = $this->addTypeRules($innerType, $config->getOption('rules'));
}

if ($innerType instanceof CollectionType) {
$rules = $this->findRules($form, $rules);
$children = $form->all();
if(isset($children[0])) {
$rules = $this->findRules($children[0], $rules, $name . '.*');
}
}
}

Expand Down

0 comments on commit 746fae0

Please sign in to comment.