mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 15:05:54 +00:00
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:
parent
2d58a9e351
commit
ad99ac8fa2
@ -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;
|
$name = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->ID . "][\\1]", $name);
|
||||||
|
$field->setName($name);
|
||||||
|
$outputFields->push($field);
|
||||||
}
|
}
|
||||||
return $output;
|
return $outputFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ClassName() {
|
function ClassName() {
|
||||||
@ -110,9 +112,16 @@ 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") {
|
||||||
$this->setField($name, $value);
|
if ($field = $fields->dataFieldByName($name)) {
|
||||||
|
$field->setValue($value);
|
||||||
|
$field->saveInto($this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->setField($name, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user