Skip to content

Commit 149a032

Browse files
committed
DefaultFormRenderer: options 'class' & 'id' are used for 'control' part when 'pair' part is empty
1 parent 37358ff commit 149a032

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ public function renderControl(Nette\Forms\IControl $control): Html
438438
if ($this->counter % 2) {
439439
$body->class($this->getValue('control .odd'), true);
440440
}
441+
if (!$this->getWrapper('pair container')->getName()) {
442+
$body->class($control->getOption('class'), true);
443+
$body->id = $control->getOption('id');
444+
}
441445

442446
$description = $control->getOption('description');
443447
if ($description instanceof IHtmlString) {

tests/Forms/Forms.renderer.1.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<p>We value your privacy and we ensure that the information you give to us will not be shared to other entities.</p>
66

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

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

tests/Forms/Forms.renderer.1.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ $form->addGroup('Personal data')
4343
->setOption('id', 'test-group-id-set-via-option');
4444

4545
$form->addText('name', 'Your name:')
46-
->addRule(Form::FILLED, 'Enter your name');
46+
->addRule(Form::FILLED, 'Enter your name')
47+
->setOption('class', 'myclass')
48+
->setOption('id', 'myid');
4749

4850
$form->addInteger('age', 'Your age:')
4951
->addRule(Form::FILLED, 'Enter your age')

tests/Forms/Forms.renderer.2.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

10-
<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>
10+
<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>
1111

1212

1313

tests/Forms/Forms.renderer.2.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ $renderer->wrappers['control']['requiredsuffix'] = " \u{2022}";
5656

5757
$form->addGroup('Personal data');
5858
$form->addText('name', 'Your name')
59-
->addRule(Form::FILLED, 'Enter your name');
59+
->addRule(Form::FILLED, 'Enter your name')
60+
->setOption('class', 'myclass')
61+
->setOption('id', 'myid');
6062

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

0 commit comments

Comments
 (0)