diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index b168bef5b..d2d73133b 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -450,6 +450,20 @@ public function renderControl(Nette\Forms\IControl $control): Html $description = $this->getValue('control requiredsuffix') . $description; } + $el = $this->doRenderControl($control); + + if ($nextTo = $control->getOption('nextTo')) { + $nextControl = $control->getForm()->getComponent($nextTo); + $nextEl = $this->doRenderControl($nextControl); + return $body->setHtml($el . $nextEl . $description . $this->renderErrors($control) . $this->renderErrors($nextControl)); + } + + return $body->setHtml($el . $description . $this->renderErrors($control)); + } + + + private function doRenderControl(Nette\Forms\IControl $control) + { $control->setOption('rendered', true); $el = $control->getControl(); if ($el instanceof Html) { @@ -458,7 +472,7 @@ public function renderControl(Nette\Forms\IControl $control): Html } $el->class($this->getValue('control .error'), $control->hasErrors()); } - return $body->setHtml($el . $description . $this->renderErrors($control)); + return $el; } diff --git a/tests/Forms/Forms.renderer.1.expect b/tests/Forms/Forms.renderer.1.expect index a87dbecee..197c414eb 100644 --- a/tests/Forms/Forms.renderer.1.expect +++ b/tests/Forms/Forms.renderer.1.expect @@ -93,13 +93,7 @@ - - - - - - - + Reenter your password diff --git a/tests/Forms/Forms.renderer.1.phpt b/tests/Forms/Forms.renderer.1.phpt index 88dfc71a7..39c9da950 100644 --- a/tests/Forms/Forms.renderer.1.phpt +++ b/tests/Forms/Forms.renderer.1.phpt @@ -86,6 +86,7 @@ $form->addSelect('countrySetItems', 'Country:') $form->addGroup('Your account'); $form->addPassword('password', 'Choose password:') + ->setOption('nextTo', 'password2') ->addRule(Form::FILLED, 'Choose your password') ->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);