Skip to content

Commit 5aa79f4

Browse files
committed
DefaultFormRenderer: supports option 'nextTo'
1 parent 7236186 commit 5aa79f4

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,20 @@ public function renderControl(Nette\Forms\IControl $control): Html
450450
$description = $this->getValue('control requiredsuffix') . $description;
451451
}
452452

453+
$el = $this->doRenderControl($control);
454+
455+
if ($nextTo = $control->getOption('nextTo')) {
456+
$nextControl = $control->getForm()->getComponent($nextTo);
457+
$nextEl = $this->doRenderControl($nextControl);
458+
return $body->setHtml($el . $nextEl . $description . $this->renderErrors($control) . $this->renderErrors($nextControl));
459+
}
460+
461+
return $body->setHtml($el . $description . $this->renderErrors($control));
462+
}
463+
464+
465+
private function doRenderControl(Nette\Forms\IControl $control)
466+
{
453467
$control->setOption('rendered', true);
454468
$el = $control->getControl();
455469
if ($el instanceof Html) {
@@ -458,7 +472,7 @@ public function renderControl(Nette\Forms\IControl $control): Html
458472
}
459473
$el->class($this->getValue('control .error'), $control->hasErrors());
460474
}
461-
return $body->setHtml($el . $description . $this->renderErrors($control));
475+
return $el;
462476
}
463477

464478

tests/Forms/Forms.renderer.1.expect

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,7 @@
9393
<tr class="required">
9494
<th><label for="frm-password" class="required">Choose password:</label></th>
9595

96-
<td><input type="password" name="password" id="frm-password" required data-nette-rules='[{"op":":filled","msg":"Choose your password"},{"op":":minLength","msg":"The password is too short: it must be at least 3 characters","arg":3}]' class="text"></td>
97-
</tr>
98-
99-
<tr>
100-
<th><label for="frm-password2">Reenter password:</label></th>
101-
102-
<td><input type="password" name="password2" id="frm-password2" data-nette-rules='[{"op":":valid","rules":[{"op":":filled","msg":"Reenter your password"},{"op":":equal","msg":"Passwords do not match","arg":{"control":"password"}}],"control":"password"}]' class="text">
96+
<td><input type="password" name="password" id="frm-password" required data-nette-rules='[{"op":":filled","msg":"Choose your password"},{"op":":minLength","msg":"The password is too short: it must be at least 3 characters","arg":3}]' class="text"><input type="password" name="password2" id="frm-password2" data-nette-rules='[{"op":":valid","rules":[{"op":":filled","msg":"Reenter your password"},{"op":":equal","msg":"Passwords do not match","arg":{"control":"password"}}],"control":"password"}]' class="text">
10397

10498
<span class="error">
10599
Reenter your password

tests/Forms/Forms.renderer.1.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ $form->addSelect('countrySetItems', 'Country:')
8686
$form->addGroup('Your account');
8787

8888
$form->addPassword('password', 'Choose password:')
89+
->setOption('nextTo', 'password2')
8990
->addRule(Form::FILLED, 'Choose your password')
9091
->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
9192

0 commit comments

Comments
 (0)