Skip to content

Commit 240c4a4

Browse files
committed
Merge pull request #38 from matej21/feature/radiolist_inner_label
RadioList: added inner label prototype [fixes #31]
2 parents 7b605c7 + ac4b82e commit 240c4a4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Forms/Controls/RadioList.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
* @property-read Nette\Utils\Html $separatorPrototype
2020
* @property-read Nette\Utils\Html $containerPrototype
21+
* @property-read Nette\Utils\Html $itemLabelPrototype
2122
*/
2223
class RadioList extends ChoiceControl
2324
{
@@ -27,6 +28,9 @@ class RadioList extends ChoiceControl
2728
/** @var Nette\Utils\Html container element template */
2829
protected $container;
2930

31+
/** @var Nette\Utils\Html item label template */
32+
protected $itemLabel;
33+
3034

3135
/**
3236
* @param string label
@@ -38,6 +42,7 @@ public function __construct($label = NULL, array $items = NULL)
3842
$this->control->type = 'radio';
3943
$this->container = Html::el();
4044
$this->separator = Html::el('br');
45+
$this->itemLabel = Html::el();
4146
}
4247

4348

@@ -71,6 +76,16 @@ public function getContainerPrototype()
7176
}
7277

7378

79+
/**
80+
* Returns item label HTML element template.
81+
* @return Nette\Utils\Html
82+
*/
83+
public function getItemLabelPrototype()
84+
{
85+
return $this->itemLabel;
86+
}
87+
88+
7489
/**
7590
* Generates control's HTML element.
7691
* @return Nette\Utils\Html
@@ -97,7 +112,7 @@ public function getControl($key = NULL)
97112
'disabled:' => $this->disabled,
98113
'data-nette-rules:' => array(key($ids) => $input->attrs['data-nette-rules']),
99114
)),
100-
array('for:' => $ids),
115+
array('for:' => $ids) + $this->itemLabel->attrs,
101116
$this->separator
102117
)
103118
);

tests/Forms/Controls.RadioList.render.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,14 @@ test(function() { // disabled one
143143
Assert::same('<label for="frm-list-a"><input type="radio" name="list" id="frm-list-a" disabled value="a">First</label><br><label for="frm-list-0"><input type="radio" name="list" id="frm-list-0" value="0">Second</label>', (string) $input->getControl());
144144
Assert::same('<input type="radio" name="list" id="frm-list-a" disabled value="a">', (string) $input->getControlPart('a'));
145145
});
146+
147+
148+
test(function() { // item label prototype
149+
$form = new Form;
150+
$input = $form->addRadioList('list', NULL, array(
151+
'a' => 'b',
152+
));
153+
$input->getItemLabelPrototype()->class("foo");
154+
155+
Assert::same('<label class="foo" for="frm-list-a"><input type="radio" name="list" id="frm-list-a" value="a">b</label>', (string) $input->getControl());
156+
});

0 commit comments

Comments
 (0)