Browse Source

Add generated classnames to labels for multiple checkboxes.

The old FormHelper code would add a classname of 'selected' to a label
when the checkbox was selected. Keep this behavior in the new widget
class.
Mark Story 12 years ago
parent
commit
25c26ffffb

+ 3 - 0
src/View/Widget/MultiCheckbox.php

@@ -153,6 +153,9 @@ class MultiCheckbox implements WidgetInterface {
 			'text' => $checkbox['text'],
 			'input' => $input,
 		];
+		if (!empty($checkbox['checked']) && empty($labelAttrs['class'])) {
+			$labelAttrs['class'] = 'selected';
+		}
 		$label = $this->_label->render($labelAttrs);
 
 		return $this->_templates->format('checkboxContainer', [

+ 1 - 1
tests/TestCase/View/Widget/MultiCheckboxTest.php

@@ -185,7 +185,7 @@ class MultiCheckboxTest extends TestCase {
 				'id' => 'tags-id-1',
 				'checked' => 'checked'
 			]],
-			['label' => ['for' => 'tags-id-1']],
+			['label' => ['class' => 'selected', 'for' => 'tags-id-1']],
 			'CakePHP',
 			'/label',
 			'/div',