From ad99ac8fa2a27d3a19c72be3cc1ce66bf91b741a Mon Sep 17 00:00:00 2001 From: Niklas Forsdahl Date: Thu, 30 Aug 2012 09:56:00 +0300 Subject: [PATCH] BUG: Enable chosen in WidgetAreaEditor fields. Fixed by having Widget::CMSEditor return a FieldList (with fields from getCMSFields) for showing DropdownFields and ListboxFields correctly, and by using FormField::saveInto() for saving the data in Widget::populateFromPostData(). --- code/model/Widget.php | 25 +++++++++++++++++-------- javascript/WidgetAreaEditor.js | 11 ----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/code/model/Widget.php b/code/model/Widget.php index 5da61e4..f4db1bd 100644 --- a/code/model/Widget.php +++ b/code/model/Widget.php @@ -88,17 +88,19 @@ class Widget extends DataObject { } function CMSEditor() { - $output = ''; $fields = $this->getCMSFields(); + $outputFields = new FieldList(); foreach($fields as $field) { $name = $field->getName(); - $field->setValue($this->getField($name)); - $renderedField = $field->FieldHolder(); - $renderedField = preg_replace("/name=\"([A-Za-z0-9\-_]+)\"/", "name=\"Widget[" . $this->ID . "][\\1]\"", $renderedField); - $renderedField = preg_replace("/id=\"([A-Za-z0-9\-_]+)\"/", "id=\"Widget[" . $this->ID . "][\\1]\"", $renderedField); - $output .= $renderedField; + $value = $this->getField($name); + if ($value) { + $field->setValue($value); + } + $name = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->ID . "][\\1]", $name); + $field->setName($name); + $outputFields->push($field); } - return $output; + return $outputFields; } function ClassName() { @@ -110,9 +112,16 @@ class Widget extends DataObject { } function populateFromPostData($data) { + $fields = $this->getCMSFields(); foreach($data as $name => $value) { if($name != "Type") { - $this->setField($name, $value); + if ($field = $fields->dataFieldByName($name)) { + $field->setValue($value); + $field->saveInto($this); + } + else { + $this->setField($name, $value); + } } } diff --git a/javascript/WidgetAreaEditor.js b/javascript/WidgetAreaEditor.js index a89d3ed..0af952a 100644 --- a/javascript/WidgetAreaEditor.js +++ b/javascript/WidgetAreaEditor.js @@ -168,17 +168,6 @@ } }); - /** - * Disable chosen - */ - $('div.usedWidgets .field.dropdown select, div.usedWidgets .field select[multiple]').entwine({ - onmatch: function() { - $(this).addClass('no-chzn'); - - this._super(); - } - }); - $('div.usedWidgets div.Widget').entwine({ onmatch: function() { // Call deleteWidget when delete button is pushed