diff --git a/src/Pluf/Form/Widget/SelectInput.php b/src/Pluf/Form/Widget/SelectInput.php index 71be75b..ef4d55f 100644 --- a/src/Pluf/Form/Widget/SelectInput.php +++ b/src/Pluf/Form/Widget/SelectInput.php @@ -22,7 +22,7 @@ # ***** END LICENSE BLOCK ***** */ /** - * Simple checkbox. + * Simple checkbox with grouping. */ class Pluf_Form_Widget_SelectInput extends Pluf_Form_Widget { @@ -53,16 +53,26 @@ class Pluf_Form_Widget_SelectInput extends Pluf_Form_Widget } $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs); $output[] = ''; - $choices = $this->choices + $choices; - foreach ($choices as $option_label=>$option_value) { - $selected = ($option_value == $value) ? ' selected="selected"':''; - $output[] = sprintf('', - htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'), - $selected, - htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8')); - + $groups = $this->choices + $choices; + foreach($groups as $option_group => $c) { + if (!is_array($c)) { + $subchoices = array($option_group => $c); + } else { + $output[] = ''; + $subchoices = $c; + } + foreach ($subchoices as $option_label=>$option_value) { + $selected = ($option_value == $value) ? ' selected="selected"':''; + $output[] = sprintf('', + htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'), + $selected, + htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8')); + } + if (is_array($c)) { + $output[] = ''; + } } $output[] = ''; return new Pluf_Template_SafeString(implode("\n", $output), true); } -} \ No newline at end of file +}