1616 *
1717 * @property-read Html $separatorPrototype
1818 * @property-read Html $containerPrototype
19+ * @property-read Html $itemLabelPrototype
1920 */
2021class CheckboxList extends MultiChoiceControl
2122{
@@ -25,6 +26,9 @@ class CheckboxList extends MultiChoiceControl
2526 /** @var Html container element template */
2627 protected $ container ;
2728
29+ /** @var Html item label template */
30+ protected $ itemLabel ;
31+
2832
2933 /**
3034 * @param string label
@@ -36,6 +40,7 @@ public function __construct($label = NULL, array $items = NULL)
3640 $ this ->control ->type = 'checkbox ' ;
3741 $ this ->container = Html::el ();
3842 $ this ->separator = Html::el ('br ' );
43+ // $this->itemLabel = Html::el('label'); back compatiblity
3944 $ this ->setOption ('type ' , 'checkbox ' );
4045 }
4146
@@ -60,7 +65,7 @@ public function getControl()
6065 'required ' => NULL ,
6166 'data-nette-rules: ' => [key ($ items ) => $ input ->attrs ['data-nette-rules ' ]],
6267 ]),
63- $ this ->label ->attrs ,
68+ $ this ->itemLabel ? $ this -> itemLabel -> attrs : $ this -> label ->attrs ,
6469 $ this ->separator
6570 )
6671 );
@@ -99,8 +104,9 @@ public function getControlPart($key = NULL)
99104 */
100105 public function getLabelPart ($ key = NULL )
101106 {
107+ $ itemLabel = $ this ->itemLabel ? clone $ this ->itemLabel : clone $ this ->label ;
102108 return func_num_args ()
103- ? parent :: getLabel ($ this ->items [$ key ])->for ($ this ->getHtmlId () . '- ' . $ key )
109+ ? $ itemLabel -> setText ($ this ->translate ( $ this -> items [$ key ]) )->for ($ this ->getHtmlId () . '- ' . $ key )
104110 : $ this ->getLabel ();
105111 }
106112
@@ -124,4 +130,14 @@ public function getContainerPrototype()
124130 return $ this ->container ;
125131 }
126132
133+
134+ /**
135+ * Returns item label HTML element template.
136+ * @return Html
137+ */
138+ public function getItemLabelPrototype ()
139+ {
140+ return $ this ->itemLabel ?: $ this ->itemLabel = Html::el ('label ' );
141+ }
142+
127143}
0 commit comments