2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grouped dropdown, using <optgroup>s.
|
|
|
|
* Returns a <select> tag containing all the appropriate <option> tags, with <optgroup> tags around the <option> tags as required
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class GroupedDropdownField extends DropdownField {
|
|
|
|
function Field() {
|
2007-09-16 18:06:24 +02:00
|
|
|
// Initialisations
|
|
|
|
$options = '';
|
|
|
|
$classAttr = '';
|
2007-07-19 12:40:28 +02:00
|
|
|
if($extraClass = trim($this->extraClass())) {
|
|
|
|
$classAttr = "class=\"$extraClass\"";
|
|
|
|
}
|
|
|
|
foreach($this->source as $value => $title) {
|
|
|
|
if(is_array($title)) {
|
|
|
|
$options .= "<optgroup label=\"$value\">";
|
|
|
|
foreach($title as $value2 => $title2) {
|
|
|
|
$selected = $value2 == $this->value ? " selected=\"selected\"" : "";
|
|
|
|
$options .= "<option$selected value=\"$value2\">$title2</option>";
|
|
|
|
}
|
|
|
|
$options .= "</optgroup>";
|
|
|
|
} else { // Fall back to the standard dropdown field
|
|
|
|
$selected = $value == $this->value ? " selected=\"selected\"" : "";
|
|
|
|
$options .= "<option$selected value=\"$value\">$title</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $this->id();
|
|
|
|
|
|
|
|
return "<select $classAttr name=\"$this->name\" id=\"$id\">$options</select>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|