Index: FormSelect.php =================================================================== --- FormSelect.php (revision 23862) +++ FormSelect.php (working copy) @@ -52,6 +52,9 @@ * multiple-select elements). * * @param array|string $attribs Attributes added to the 'select' tag. + * the optional 'optionClasses' attribute is used to add a class to + * the options within the select (associative array linking the option + * value to the desired class) * * @param array $options An array of key-value pairs where the array * key is the radio value, and the array value is the radio text. @@ -96,6 +99,13 @@ unset($attribs['multiple']); } + // handle the options classes + $optionClasses = array(); + if (isset($attribs['optionClasses'])) { + $optionClasses = $attribs['optionClasses']; + unset($attribs['optionClasses']); + } + // now start building the XHTML. $disabled = ''; if (true === $disable) { @@ -127,11 +137,11 @@ . $opt_disable . ' label="' . $this->view->escape($opt_value) .'">'; foreach ($opt_label as $val => $lab) { - $list[] = $this->_build($val, $lab, $value, $disable); + $list[] = $this->_build($val, $lab, $value, $disable, $optionClasses); } $list[] = ''; } else { - $list[] = $this->_build($opt_value, $opt_label, $value, $disable); + $list[] = $this->_build($opt_value, $opt_label, $value, $disable, $optionClasses); } } @@ -148,18 +158,28 @@ * @param string $label Options Label * @param array $selected The option value(s) to mark as 'selected' * @param array|bool $disable Whether the select is disabled, or individual options are + * @param array $optionClasses The classes to associate with each option value * @return string Option Tag XHTML */ - protected function _build($value, $label, $selected, $disable) + protected function _build($value, $label, $selected, $disable, $optionClasses = array()) { if (is_bool($disable)) { $disable = array(); } + $class = null; + if (array_key_exists($value, $optionClasses)) { + $class = $optionClasses[$value]; + } + + $opt = '