[Solar-talk] FormSelect: optgroups
Rodrigo Moraes
rodrigo.moraes at gmail.com
Thu Aug 24 08:27:33 PDT 2006
You know, the FormSelect helper doesn't allow optgroups. I've hacked
it to allow groups. When an option label is an array, it uses the
option value as the group label and the label as the options array. It
is dirty, but it works. :-)
if(is_array($opt_label)) {
$list[] = '<optgroup label="' . $opt_value . '">';
foreach ($opt_label as $opt_group_value => $opt_group_label) {
$selected = '';
if (in_array($opt_group_label, $this->_value)) {
$selected = ' selected="selected"';
}
$list[] = '<option'
. ' value="' . $this->_view->escape($opt_group_value) . '"'
. ' label="' . $this->_view->escape($opt_group_label) . '"'
. $selected
. '>' . $this->_view->escape($opt_group_label) . "</option>";
}
$list[] = '</optgroup>';
} else {
... current FormSelect options building ...
cheers,
rodrigo
More information about the solar-talk
mailing list