diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 7bc173fbd..2392a7b28 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -123,6 +123,15 @@ public function getValues($returnType = null, ?array $controls = null) if ($controls === null && $submitter instanceof SubmitterControl) { $controls = $submitter->getValidationScope(); + if ($controls !== null && !in_array($this, $controls, true)) { + $scope = $this; + while (($scope = $scope->getParent()) instanceof self) { + if (in_array($scope, $controls, true)) { + $controls[] = $this; + break; + } + } + } } } @@ -155,7 +164,7 @@ public function getUntrustedValues($returnType = ArrayHash::class, ?array $contr } foreach ($this->getComponents() as $name => $control) { - $allowed = $controls === null || in_array($control, $controls, true); + $allowed = $controls === null || in_array($this, $controls, true) || in_array($control, $controls, true); $name = (string) $name; if ( $control instanceof Control diff --git a/tests/Forms/Container.values.array.phpt b/tests/Forms/Container.values.array.phpt index 417f2259d..d8ec2d18a 100644 --- a/tests/Forms/Container.values.array.phpt +++ b/tests/Forms/Container.values.array.phpt @@ -283,6 +283,23 @@ test('submitted form + setValidationScope() + getValues(true)', function () { $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['send'] = ''; + $form = createForm(); + $form->addSubmit('send')->setValidationScope([$form['first']]); + + Assert::truthy($form->isSubmitted()); + Assert::equal([ + 'name' => '', + 'age' => 999, + 'second' => [ + 'city' => 'sent city', + ], + ], $form['first']->getValues('array')); +}); + +test('submitted form + setValidationScope() + getValues(array)', function () { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['send'] = ''; + $form = createForm(); $form->addSubmit('send')->setValidationScope([$form['title'], $form['first']['second']]);