mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Tidied up DropdownField->Field() by making use of FormField->createTag() as other FormField subclasses such as TextField do
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63289 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
57ad2dd372
commit
11e09aa0d6
@ -30,26 +30,36 @@ class DropdownField extends FormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a <select> tag containing all the appropriate <option> tags
|
* Returns a <select> tag containing all the appropriate <option> tags.
|
||||||
|
* Makes use of {@link FormField->createTag()} to generate the <select>
|
||||||
|
* tag and option elements inside is as the content of the <select>.
|
||||||
|
*
|
||||||
|
* @return string HTML tag for this dropdown field
|
||||||
*/
|
*/
|
||||||
function Field() {
|
function Field() {
|
||||||
$classAttr = '';
|
|
||||||
$options = '';
|
$options = '';
|
||||||
if($extraClass = trim($this->extraClass())) {
|
|
||||||
$classAttr = "class=\"$extraClass\"";
|
|
||||||
}
|
|
||||||
if($this->source) foreach($this->source as $value => $title) {
|
if($this->source) foreach($this->source as $value => $title) {
|
||||||
$selected = $value == $this->value ? " selected=\"selected\"" : "";
|
$selected = $value == $this->value ? 'selected' : null;
|
||||||
if($selected && $this->value != 0) {
|
if($selected && $this->value != 0) {
|
||||||
$this->isSelected = true;
|
$this->isSelected = true;
|
||||||
}
|
}
|
||||||
$options .= "<option$selected value=\"$value\">$title</option>";
|
|
||||||
|
$options .= $this->createTag('option', array(
|
||||||
|
'selected' => $selected,
|
||||||
|
'value' => $value
|
||||||
|
), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $this->id();
|
$attributes = array(
|
||||||
$disabled = $this->disabled ? " disabled=\"disabled\"" : "";
|
'class' => trim($this->extraClass()) ? $this->extraClass() : null,
|
||||||
|
'id' => $this->id(),
|
||||||
|
'name' => $this->name,
|
||||||
|
'disabled' => $this->disabled ? 'disabled' : null,
|
||||||
|
'tabindex' => $this->getTabIndex()
|
||||||
|
);
|
||||||
|
|
||||||
return "<select $classAttr $disabled name=\"$this->name\" id=\"$id\"" . $this->getTabIndexHTML() . ">$options</select>";
|
return $this->createTag('select', $attributes, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSelected(){
|
function isSelected(){
|
||||||
|
Loading…
Reference in New Issue
Block a user