diff --git a/src/Helper/Input/Checkbox.php b/src/Helper/Input/Checkbox.php index dc06364..f78669c 100644 --- a/src/Helper/Input/Checkbox.php +++ b/src/Helper/Input/Checkbox.php @@ -17,6 +17,33 @@ */ class Checkbox extends AbstractChecked { + + /** + * + * Individual attributes for each option (only for multi checkbox) + * + * @var array + * + */ + protected $options_attribs = array(); + + /** + * + * Prepares the properties on this helper. + * + * @param array $spec The specification array. + * + */ + protected function prep(array $spec) + { + if (isset($spec['options_attribs'])) { + $this->options_attribs = $spec['options_attribs']; + unset($spec['options_attribs']); + } + + parent::prep($spec); + } + /** * * Returns the HTML for the input. @@ -80,10 +107,12 @@ protected function multiple() $this->attribs['value'] = $value; $this->attribs['label'] = $label; + $option_attribs = isset($this->options_attribs[$value]) ? $this->options_attribs[$value] : array(); + $html .= $checkbox(array( 'name' => $this->attribs['name'], 'value' => $this->value, - 'attribs' => $this->attribs + 'attribs' => $this->attribs + $option_attribs )); } return $html; diff --git a/tests/Helper/Input/CheckboxTest.php b/tests/Helper/Input/CheckboxTest.php index d3a004b..ec104a8 100644 --- a/tests/Helper/Input/CheckboxTest.php +++ b/tests/Helper/Input/CheckboxTest.php @@ -170,4 +170,28 @@ public function testMultiCheckboxWithValues() { . '' . PHP_EOL; $this->assertSame($expect, $actual); } + + public function testOptionAttributes() { + $checkbox = $this->helper; + $actual = $checkbox(array( + 'name' => 'foo', + 'value' => 'yes', + 'options' => array( + 'yes' => 'Yes', + 'no' => 'No', + ), + 'options_attribs' => array( + 'yes' => array( + 'class' => 'test-class' + ), + 'no' => array( + 'data-no' => 1 + ), + ), + ))->__toString(); + $expect = '' . PHP_EOL + . '' . PHP_EOL; + $this->assertSame($expect, $actual); + } + }