Reverted r61492

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61497 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2008-08-25 23:32:12 +00:00
parent 8dff62d3cb
commit 413b309d17
2 changed files with 30 additions and 37 deletions

View File

@ -10,17 +10,6 @@ class DropdownField extends FormField {
/**
* Creates a new dropdown field.
*
* $source parameter can be a two dimensional array; creating <optgroup> elements
* as needed for the first level of the array, and <option> elements for the second
* level.
*
* If the source array is of a single dimension, then the dropdown just contains
* <option> tags as required for each of the items in the source.
*
* Returns a <select> tag containing all the appropriate <option> and <optgroup>
* as required from the source.
*
* @param $name The field name
* @param $title The field title
* @param $source An map of the dropdown items
@ -46,31 +35,15 @@ class DropdownField extends FormField {
function Field() {
$classAttr = '';
$options = '';
if($extraClass = trim($this->extraClass())) {
$classAttr = "class=\"$extraClass\"";
}
if($this->source) {
foreach($this->source as $value => $title) {
if(is_array($title)) { // Nested array, create an optgroup
$options .= "<optgroup label=\"$value\">";
foreach($title as $value2 => $title2) {
$selected = $value2 == $this->value ? " selected=\"selected\"" : "";
if($selected && $this->value != 0) {
$this->isSelected = true;
}
$options .= "<option$selected value=\"$value2\">$title2</option>";
}
$options .= "</optgroup>";
} else { // Fall back to the standard dropdown field
$selected = $value == $this->value ? " selected=\"selected\"" : "";
if($selected && $this->value != 0) {
$this->isSelected = true;
}
$options .= "<option$selected value=\"$value\">$title</option>";
}
if($this->source) foreach($this->source as $value => $title) {
$selected = $value == $this->value ? " selected=\"selected\"" : "";
if($selected && $this->value != 0) {
$this->isSelected = true;
}
$options .= "<option$selected value=\"$value\">$title</option>";
}
$id = $this->id();

View File

@ -1,10 +1,7 @@
<?php
/**
* Grouped dropdown, using <optgroup> tags.
*
* @deprecated - Please use DropdownField instead!
*
* $source parameter (from DropdownField) must be a two dimensional array.
* The first level of the array is used for the <optgroup>, and the second
* level are the <options> for each group.
@ -18,9 +15,32 @@
class GroupedDropdownField extends DropdownField {
function Field() {
user_error('GroupedDropdownField is deprecated. Please use DropdownField instead.', E_USER_NOTICE);
// Initialisations
$options = '';
$classAttr = '';
return parent::Field();
if($extraClass = trim($this->extraClass())) {
$classAttr = "class=\"$extraClass\"";
}
if($this->source) {
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>";
}
}