|
|
@@ -52,6 +52,9 @@ class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
|
|
|
* 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 @@ class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
|
|
|
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) {
|
|
|
@@ -130,11 +140,11 @@ class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
|
|
|
. $opt_id
|
|
|
. ' 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[] = '</optgroup>';
|
|
|
} else {
|
|
|
- $list[] = $this->_build($opt_value, $opt_label, $value, $disable);
|
|
|
+ $list[] = $this->_build($opt_value, $opt_label, $value, $disable, $optionClasses);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -151,18 +161,28 @@ class Zend_View_Helper_FormSelect extends Zend_View_Helper_FormElement
|
|
|
* @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 = '<option'
|
|
|
. ' value="' . $this->view->escape($value) . '"'
|
|
|
. ' label="' . $this->view->escape($label) . '"';
|
|
|
|
|
|
+ if ($class) {
|
|
|
+ $opt .= ' class="' . $class . '"';
|
|
|
+ }
|
|
|
// selected?
|
|
|
if (in_array((string) $value, $selected)) {
|
|
|
$opt .= ' selected="selected"';
|