1 <?php
2
3 4 5 6 7
8
9 class HTMLDropdownField extends DropdownField
10 {
11 12 13 14 15 16 17
18 function Field() {
19 $options = '';
20
21 $source = $this->getSource();
22 if($source) {
23
24 if(is_object($source) && $this->emptyString) {
25 $options .= $this->createTag('option', array('value' => ''), $this->emptyString);
26 }
27
28 foreach($source as $value => $title) {
29
30
31 if($value === '' && ($this->value === '' || $this->value === null)) {
32 $selected = 'selected';
33 } else {
34
35 if($value) {
36 $selected = ($value == $this->value) ? 'selected' : null;
37 } else {
38
39 $selected = ($value === $this->value) ? 'selected' : null;
40 }
41
42 $this->isSelected = ($selected) ? true : false;
43 }
44
45 $options .= $this->createTag(
46 'option',
47 array(
48 'selected' => $selected,
49 'value' => $value
50 ),
51 $title
52 );
53 }
54 }
55
56 $attributes = array(
57 'class' => ($this->extraClass() ? $this->extraClass() : ''),
58 'id' => $this->id(),
59 'name' => $this->name,
60 'tabindex' => $this->getTabIndex()
61 );
62
63 if($this->disabled) $attributes['disabled'] = 'disabled';
64
65 return $this->createTag('select', $attributes, $options);
66 }
67
68 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-