1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15 class GroupedDropdownField extends DropdownField {
16
17 function Field() {
18
19 $options = array();
20 foreach($this->getSource() as $value => $title) {
21 if(is_array($title)) {
22
23 $items = array();
24 foreach($title as $value2 => $title2) {
25 $selected = ($value2 == $this->value);
26
27 $items[] = new ArrayData(array(
28 'Value' => $value2,
29 'Title' => Convert::raw2xml($title2),
30 'Selected' => $selected,
31 ));
32 }
33 $options[] = new ArrayData(array(
34 'Value' => $value,
35 'Items' => new DataObjectSet($items),
36 ));
37
38 } else {
39 $selected = ($value == $this->value);
40 $options[] = new ArrayData(array(
41 'Value' => $value,
42 'Title' => Convert::raw2xml($title),
43 'Selected' => $selected,
44 ));
45 }
46 }
47 $attributes = array(
48 'class' => ($this->extraClass() ? $this->extraClass() : ''),
49 'id' => $this->id(),
50 'name' => $this->name,
51 'tabindex' => $this->getTabIndex(),
52 );
53 if($this->disabled) $attributes['disabled'] = 'disabled';
54 return $this->createTag('select', $attributes, new DataObjectSet($options));
55
56
57 return "<select $classAttr name=\"$this->name\" id=\"$id\">$options</select>";
58 }
59 }
60
61 ?>
[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.
-