From f292d493bed7d10b4c4c3c7c42abddc14f6ef0e8 Mon Sep 17 00:00:00 2001 From: Christian Weber Date: Tue, 25 Sep 2007 01:30:44 +0000 Subject: Add support for multi-select in select() --- it_html.class | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/it_html.class b/it_html.class index e4d7245..56918e1 100644 --- a/it_html.class +++ b/it_html.class @@ -313,7 +313,7 @@ function img($args) * @param $options array (value => text) of available options or * string key:val{,key:val} where key will be rawurldecoded so it may contain %2C as comma * supports optgroups as array (value => optgroup => array(value => text)) - * @param $selected optional currently selected value + * @param $selected optional currently selected value, or comma-separated list or array for multi-select */ function select($tags, $options, $selected = null) { @@ -330,6 +330,8 @@ function select($tags, $options, $selected = null) } } + $selected = (isset($selected) && !is_array($selected)) ? explode(',', $selected) : (array)$selected; + $html = ""; foreach($options as $value => $option) { @@ -337,11 +339,11 @@ function select($tags, $options, $selected = null) { $grouphtml = ""; foreach($option as $optval => $opt) - $grouphtml .= $this->_tag("option", array(array('value' => $optval, 'selected' => isset($selected) ? $optval == $selected : false), Q($opt))); + $grouphtml .= $this->_tag("option", array(array('value' => $optval, 'selected' => in_array($optval, $selected)), Q($opt))); $html .= $this->_tag("optgroup", array(array('label' => $value, $grouphtml))); } else - $html .= $this->_tag("option", array(array('value' => $value, 'selected' => isset($selected) ? $value == $selected : false, 'disabled' => $option === ""), (trim($option) === "") ? " " : Q($option))); + $html .= $this->_tag("option", array(array('value' => $value, 'selected' => in_array($value, $selected), 'disabled' => $option === ""), (trim($option) === "") ? " " : Q($option))); } return $this->_tag("select", array($tags, $html)); -- cgit v1.2.3