diff --git a/forms/GroupedDropdownField.php b/forms/GroupedDropdownField.php
index 6e24a5012..2d30956e5 100644
--- a/forms/GroupedDropdownField.php
+++ b/forms/GroupedDropdownField.php
@@ -56,32 +56,52 @@
class GroupedDropdownField extends DropdownField {
public function Field($properties = array()) {
- $options = '';
- foreach($this->getSource() as $value => $title) {
- if(is_array($title)) {
- $options .= "";
- } else { // Fall back to the standard dropdown field
- $disabled = '';
- if( in_array($value, $this->disabledItems) ){
- $disabled = 'disabled="disabled"';
- }
- $selected = $value == $this->value ? " selected=\"selected\"" : "";
- $options .= "";
+
+ $options[] = array(
+ 'Title' => $valueOrGroupTitle,
+ 'Options' => new ArrayList($groupOptions),
+ );
+ } else {
+ // Single option
+ $disabled = in_array($valueOrGroupTitle, $this->disabledItems);
+
+ $options[] = array(
+ 'Value' => $valueOrGroupTitle,
+ 'Disabled' => $disabled,
+ 'Title' => $titleOrGroup,
+ 'Selected' => $valueOrGroupTitle == $this->value
+ );
}
}
- return FormField::create_tag('select', $this->getAttributes(), $options);
+ // Render
+ $this->extend('onBeforeRender', $this);
+ $properties = array_merge($properties, array(
+ 'Options' => new ArrayList($options)
+ ));
+ return $this
+ ->customise($properties)
+ ->renderWith($this->getTemplates());
}
public function Type() {
diff --git a/templates/Includes/GroupedDropdownFieldOption.ss b/templates/Includes/GroupedDropdownFieldOption.ss
new file mode 100644
index 000000000..69a34cd39
--- /dev/null
+++ b/templates/Includes/GroupedDropdownFieldOption.ss
@@ -0,0 +1,12 @@
+<% if $Options %>
+
+<% else %>
+
+<% end_if %>
diff --git a/templates/forms/GroupedDropdownField.ss b/templates/forms/GroupedDropdownField.ss
new file mode 100644
index 000000000..827f362f2
--- /dev/null
+++ b/templates/forms/GroupedDropdownField.ss
@@ -0,0 +1,5 @@
+
diff --git a/tests/forms/GroupedDropdownFieldTest.php b/tests/forms/GroupedDropdownFieldTest.php
index e15b623b4..fa7701bc5 100644
--- a/tests/forms/GroupedDropdownFieldTest.php
+++ b/tests/forms/GroupedDropdownFieldTest.php
@@ -51,4 +51,22 @@ class GroupedDropdownFieldTest extends SapphireTest {
$this->assertFalse($field->validate($validator));
}
+ public function testRendering() {
+ $field = GroupedDropdownField::create('Test', 'Testing', array(
+ "1" => "One",
+ "Group One" => array(
+ "2" => "Two",
+ "3" => "Three"
+ ),
+ "Group Two" => array(
+ "4" => "Four"
+ )
+ ));
+ $body= $field->Field()->forTemplate();
+ $this->assertContains('