1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette,
11: Nette\Utils\Html;
12:
13:
14: 15: 16: 17: 18: 19: 20: 21:
22: class RadioList extends ChoiceControl
23: {
24:
25: protected $separator;
26:
27:
28: protected $container;
29:
30:
31: 32: 33: 34:
35: public function __construct($label = NULL, array $items = NULL)
36: {
37: parent::__construct($label, $items);
38: $this->control->type = 'radio';
39: $this->container = Html::el();
40: $this->separator = Html::el('br');
41: }
42:
43:
44: 45: 46: 47:
48: public function getValue()
49: {
50: return parent::getValue();
51: }
52:
53:
54: 55: 56: 57:
58: public function getSeparatorPrototype()
59: {
60: return $this->separator;
61: }
62:
63:
64: 65: 66: 67:
68: public function getContainerPrototype()
69: {
70: return $this->container;
71: }
72:
73:
74: 75: 76: 77:
78: public function getControl($key = NULL)
79: {
80: if ($key !== NULL) {
81: trigger_error(sprintf('Partial %s() is deprecated; use getControlPart() instead.', __METHOD__), E_USER_DEPRECATED);
82: return $this->getControlPart($key);
83: }
84:
85: $input = parent::getControl();
86: $ids = array();
87: foreach ($this->getItems() as $value => $label) {
88: $ids[$value] = $input->id . '-' . $value;
89: }
90:
91: return $this->container->setHtml(
92: Nette\Forms\Helpers::createInputList(
93: $this->translate($this->getItems()),
94: array_merge($input->attrs, array(
95: 'id:' => $ids,
96: 'checked?' => $this->value,
97: 'disabled:' => $this->disabled,
98: 'data-nette-rules:' => array(key($ids) => $input->attrs['data-nette-rules']),
99: )),
100: array('for:' => $ids),
101: $this->separator
102: )
103: );
104: }
105:
106:
107: 108: 109: 110: 111:
112: public function getLabel($caption = NULL, $key = NULL)
113: {
114: if ($key !== NULL) {
115: trigger_error(sprintf('Partial %s() is deprecated; use getLabelPart() instead.', __METHOD__), E_USER_DEPRECATED);
116: return $this->getLabelPart($key);
117: }
118: return parent::getLabel($caption)->for(NULL);
119: }
120:
121:
122: 123: 124:
125: public function getControlPart($key)
126: {
127: return parent::getControl()->addAttributes(array(
128: 'id' => $this->getHtmlId() . '-' . $key,
129: 'checked' => in_array($key, (array) $this->value, TRUE),
130: 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled,
131: 'value' => $key,
132: ));
133: }
134:
135:
136: 137: 138:
139: public function getLabelPart($key)
140: {
141: return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
142: }
143:
144: }
145: