Skip to content

Commit c8c275d

Browse files
committed
DefaultFormRenderer: options 'class' & 'id' are used for 'control' part when 'pair' part is empty
1 parent ee132bf commit c8c275d

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
@@ -431,6 +431,10 @@ public function renderControl(Nette\Forms\IControl $control): Html
431431
if ($this->counter % 2) {
432432
$body->class($this->getValue('control .odd'), true);
433433
}
434+
if (!$this->getWrapper('pair container')->getName()) {
435+
$body->class($control->getOption('class'), true);
436+
$body->id = $control->getOption('id');
437+
}
434438

435439
$description = $control->getOption('description');
436440
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
@@ -55,7 +55,9 @@ $renderer->wrappers['control']['requiredsuffix'] = " \u{2022}";
5555

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

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

0 commit comments

Comments
 (0)