Skip to content

Commit

Permalink
DefaultFormRenderer: options 'class' & 'id' are used for 'control' pa…
Browse files Browse the repository at this point in the history
…rt when 'pair' part is empty
  • Loading branch information
dg committed Mar 25, 2020
1 parent ee132bf commit c8c275d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Forms/Rendering/DefaultFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ public function renderControl(Nette\Forms\IControl $control): Html
if ($this->counter % 2) {
$body->class($this->getValue('control .odd'), true);
}
if (!$this->getWrapper('pair container')->getName()) {
$body->class($control->getOption('class'), true);
$body->id = $control->getOption('id');
}

$description = $control->getOption('description');
if ($description instanceof IHtmlString) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Forms.renderer.1.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p>We value your privacy and we ensure that the information you give to us will not be shared to other entities.</p>

<table>
<tr class="required">
<tr class="required myclass" id="myid">
<th><label for="frm-name" class="required">Your name:</label></th>

<td><input type="text" name="name" id="frm-name" required data-nette-rules='[{"op":":filled","msg":"Enter your name"}]' value="John Doe" class="text"></td>
Expand Down
4 changes: 3 additions & 1 deletion tests/Forms/Forms.renderer.1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ $form->addGroup('Personal data')
->setOption('id', 'test-group-id-set-via-option');

$form->addText('name', 'Your name:')
->addRule(Form::FILLED, 'Enter your name');
->addRule(Form::FILLED, 'Enter your name')
->setOption('class', 'myclass')
->setOption('id', 'myid');

$form->addInteger('age', 'Your age:')
->addRule(Form::FILLED, 'Enter your age')
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Forms.renderer.2.expect
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<dt><label for="frm-name" class="required">Your name:</label></dt>

<dd><input type="text" name="name" id="frm-name" required data-nette-rules='[{"op":":filled","msg":"Enter your name"}]' value="John Doe" class="text"> •</dd>
<dd class="myclass" id="myid"><input type="text" name="name" id="frm-name" required data-nette-rules='[{"op":":filled","msg":"Enter your name"}]' value="John Doe" class="text"> •</dd>



Expand Down
4 changes: 3 additions & 1 deletion tests/Forms/Forms.renderer.2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ $renderer->wrappers['control']['requiredsuffix'] = " \u{2022}";

$form->addGroup('Personal data');
$form->addText('name', 'Your name')
->addRule(Form::FILLED, 'Enter your name');
->addRule(Form::FILLED, 'Enter your name')
->setOption('class', 'myclass')
->setOption('id', 'myid');

$form->addText('age', 'Your age')
->addRule(Form::FILLED, 'Enter your age')
Expand Down

0 comments on commit c8c275d

Please sign in to comment.