Skip to content

Commit

Permalink
DefaultFormRenderer: supports option 'nextTo'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 23, 2020
1 parent bdfb7de commit f9cd919
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/Forms/Rendering/DefaultFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}


Expand Down
8 changes: 1 addition & 7 deletions tests/Forms/Forms.renderer.1.expect
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@
<tr class="required">
<th><label for="frm-password" class="required">Choose password:</label></th>

<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>
</tr>

<tr>
<th><label for="frm-password2">Reenter password:</label></th>

<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">
<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">

<span class="error">
Reenter your password
Expand Down
1 change: 1 addition & 0 deletions tests/Forms/Forms.renderer.1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f9cd919

Please sign in to comment.