Skip to content
Permalink
Browse files

DefaultFormRenderer: supports option 'nextTo'

  • Loading branch information
dg committed Jan 14, 2020
1 parent 62e485e commit b2b47dee500a92826b8d1fd6fb694c37dd8ad8d7
@@ -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;
}


@@ -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
@@ -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);

0 comments on commit b2b47de

Please sign in to comment.
You can’t perform that action at this time.