1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette;
11: use Nette\Utils\Html;
12:
13:
14: 15: 16: 17: 18: 19: 20:
21: class CheckboxList extends MultiChoiceControl
22: {
23:
24: protected $separator;
25:
26:
27: public function __construct($label = NULL, array $items = NULL)
28: {
29: parent::__construct($label, $items);
30: $this->control->type = 'checkbox';
31: $this->separator = Html::el('br');
32: }
33:
34:
35: 36: 37: 38:
39: public function getControl()
40: {
41: $items = $this->getItems();
42: reset($items);
43: $input = parent::getControl();
44: return Nette\Forms\Helpers::createInputList(
45: $this->translate($items),
46: array_merge($input->attrs, array(
47: 'id' => NULL,
48: 'checked?' => $this->value,
49: 'disabled:' => $this->disabled,
50: 'required' => NULL,
51: 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']),
52: )),
53: $this->label->attrs,
54: $this->separator
55: );
56: }
57:
58:
59: 60: 61: 62: 63:
64: public function getLabel($caption = NULL)
65: {
66: return parent::getLabel($caption)->for(NULL);
67: }
68:
69:
70: 71: 72: 73:
74: public function getSeparatorPrototype()
75: {
76: return $this->separator;
77: }
78:
79:
80: 81: 82:
83: public function getControlPart($key)
84: {
85: return parent::getControl()->addAttributes(array(
86: 'id' => $this->getHtmlId() . '-' . $key,
87: 'checked' => in_array($key, (array) $this->value, TRUE),
88: 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled,
89: 'required' => NULL,
90: 'value' => $key,
91: ));
92: }
93:
94:
95: 96: 97:
98: public function getLabelPart($key)
99: {
100: return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
101: }
102:
103: }
104: