summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weber2007-09-25 01:30:44 +0000
committerChristian Weber2007-09-25 01:30:44 +0000
commitf292d493bed7d10b4c4c3c7c42abddc14f6ef0e8 (patch)
tree95d8e4cf9254e45dc0222172679ad2d35a41829a
parent47af49faf2d4f65c87cb9d6ac4e731246fe848cd (diff)
downloaditools-f292d493bed7d10b4c4c3c7c42abddc14f6ef0e8.tar.gz
itools-f292d493bed7d10b4c4c3c7c42abddc14f6ef0e8.tar.bz2
itools-f292d493bed7d10b4c4c3c7c42abddc14f6ef0e8.zip
Add support for multi-select in select()
-rw-r--r--it_html.class8
1 files 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));