diff --git a/src/Forms/Controls/SubmitButton.php b/src/Forms/Controls/SubmitButton.php index 69d7eb98..fd7cdc2f 100644 --- a/src/Forms/Controls/SubmitButton.php +++ b/src/Forms/Controls/SubmitButton.php @@ -59,28 +59,33 @@ public function isSubmittedBy(): bool /** * Sets the validation scope. Clicking the button validates only the controls within the specified scope. + * @param ?iterable */ public function setValidationScope(?iterable $scope): static { if ($scope === null) { $this->validationScope = null; - } else { - $this->validationScope = []; - foreach ($scope ?: [] as $control) { - if (!$control instanceof Nette\Forms\Container && !$control instanceof Nette\Forms\Control) { - throw new Nette\InvalidArgumentException('Validation scope accepts only Nette\Forms\Container or Nette\Forms\Control instances.'); - } - - $this->validationScope[] = $control; - } + return $this; } + $this->validationScope = []; + foreach ($scope as $control) { + if (is_string($control)) { + $control = $this->getForm()->getComponent($control); + } + if (!$control instanceof Nette\Forms\Container && !$control instanceof Nette\Forms\Control) { + throw new Nette\InvalidArgumentException('Validation scope accepts only Nette\Forms\Container or Nette\Forms\Control instances.'); + } + + $this->validationScope[] = $control; + } return $this; } /** * Gets the validation scope. + * @return ?array */ public function getValidationScope(): ?array { diff --git a/tests/Forms/Forms.validationScope.phpt b/tests/Forms/Forms.validationScope.phpt index 4dfc8a56..df12ef05 100644 --- a/tests/Forms/Forms.validationScope.phpt +++ b/tests/Forms/Forms.validationScope.phpt @@ -41,7 +41,7 @@ foreach ($datasets as $case) { $form->addSubmit('send1'); $form->addSubmit('send2')->setValidationScope([]); $form->addSubmit('send3')->setValidationScope([$form['name']]); - $form->addSubmit('send4')->setValidationScope([$form['details']['age']]); + $form->addSubmit('send4')->setValidationScope(['details-age']); $form->addSubmit('send5')->setValidationScope([$form['details']]); $form->setSubmittedBy($form[$case[0]]);