Permalink
Browse files

RadioList: added item label prototype [fixes #31]

  • Loading branch information...
1 parent 7b605c7 commit ac4b82ea38c271db05bd0cac4db5eb1230ccc3a1 @matej21 matej21 committed Sep 7, 2014
Showing with 27 additions and 1 deletion.
  1. +16 โˆ’1 src/Forms/Controls/RadioList.php
  2. +11 โˆ’0 tests/Forms/Controls.RadioList.render.phpt
@@ -18,6 +18,7 @@
*
* @property-read Nette\Utils\Html $separatorPrototype
* @property-read Nette\Utils\Html $containerPrototype
+ * @property-read Nette\Utils\Html $itemLabelPrototype
*/
class RadioList extends ChoiceControl
{
@@ -27,6 +28,9 @@ class RadioList extends ChoiceControl
/** @var Nette\Utils\Html container element template */
protected $container;
+ /** @var Nette\Utils\Html item label template */
+ protected $itemLabel;
+
/**
* @param string label
@@ -38,6 +42,7 @@ public function __construct($label = NULL, array $items = NULL)
$this->control->type = 'radio';
$this->container = Html::el();
$this->separator = Html::el('br');
+ $this->itemLabel = Html::el();
}
@@ -72,6 +77,16 @@ public function getContainerPrototype()
/**
+ * Returns item label HTML element template.
+ * @return Nette\Utils\Html
+ */
+ public function getItemLabelPrototype()
+ {
+ return $this->itemLabel;
+ }
+
+
+ /**
* Generates control's HTML element.
* @return Nette\Utils\Html
*/
@@ -97,7 +112,7 @@ public function getControl($key = NULL)
'disabled:' => $this->disabled,
'data-nette-rules:' => array(key($ids) => $input->attrs['data-nette-rules']),
)),
- array('for:' => $ids),
+ array('for:' => $ids) + $this->itemLabel->attrs,
$this->separator
)
);
@@ -143,3 +143,14 @@ test(function() { // disabled one
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());
Assert::same('<input type="radio" name="list" id="frm-list-a" disabled value="a">', (string) $input->getControlPart('a'));
});
+
+
+test(function() { // item label prototype
+ $form = new Form;
+ $input = $form->addRadioList('list', NULL, array(
+ 'a' => 'b',
+ ));
+ $input->getItemLabelPrototype()->class("foo");
+
+ 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());
+});

0 comments on commit ac4b82e

Please sign in to comment.