Form now loads correctly when ClassName is changed.

This commit is contained in:
Nik Rolls 2013-04-02 15:09:52 +13:00 committed by Ingo Schommer
parent c08ab18c03
commit 5143c8149a

View File

@ -455,6 +455,16 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
if(!$this->record->canEdit()) {
return $controller->httpError(403);
}
if (isset($data['ClassName']) && $data['ClassName'] != $this->record->ClassName) {
$newClassName = $data['ClassName'];
// The records originally saved attribute was overwritten by $form->saveInto($record) before.
// This is necessary for newClassInstance() to work as expected, and trigger change detection
// on the ClassName attribute
$this->record->setClassName($this->record->ClassName);
// Replace $record with a new instance
$this->record = $this->record->newClassInstance($newClassName);
}
try {
$form->saveInto($this->record);