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().
This commit is contained in:
Niklas Forsdahl 2012-08-30 09:56:00 +03:00
parent 2d58a9e351
commit ad99ac8fa2
2 changed files with 17 additions and 19 deletions

View File

@ -88,17 +88,19 @@ class Widget extends DataObject {
} }
function CMSEditor() { function CMSEditor() {
$output = '';
$fields = $this->getCMSFields(); $fields = $this->getCMSFields();
$outputFields = new FieldList();
foreach($fields as $field) { foreach($fields as $field) {
$name = $field->getName(); $name = $field->getName();
$field->setValue($this->getField($name)); $value = $this->getField($name);
$renderedField = $field->FieldHolder(); if ($value) {
$renderedField = preg_replace("/name=\"([A-Za-z0-9\-_]+)\"/", "name=\"Widget[" . $this->ID . "][\\1]\"", $renderedField); $field->setValue($value);
$renderedField = preg_replace("/id=\"([A-Za-z0-9\-_]+)\"/", "id=\"Widget[" . $this->ID . "][\\1]\"", $renderedField);
$output .= $renderedField;
} }
return $output; $name = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->ID . "][\\1]", $name);
$field->setName($name);
$outputFields->push($field);
}
return $outputFields;
} }
function ClassName() { function ClassName() {
@ -110,11 +112,18 @@ class Widget extends DataObject {
} }
function populateFromPostData($data) { function populateFromPostData($data) {
$fields = $this->getCMSFields();
foreach($data as $name => $value) { foreach($data as $name => $value) {
if($name != "Type") { if($name != "Type") {
if ($field = $fields->dataFieldByName($name)) {
$field->setValue($value);
$field->saveInto($this);
}
else {
$this->setField($name, $value); $this->setField($name, $value);
} }
} }
}
$this->write(); $this->write();

View File

@ -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({ $('div.usedWidgets div.Widget').entwine({
onmatch: function() { onmatch: function() {
// Call deleteWidget when delete button is pushed // Call deleteWidget when delete button is pushed