BUG Gridfield fails when save changes filter criteria (fixes #7785)

This commit is contained in:
Ingo Schommer 2012-09-02 16:57:50 +02:00
parent d24ea5ec97
commit 52263e6a5f

View File

@ -364,6 +364,7 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
function doSave($data, $form) {
$new_record = $this->record->ID == 0;
$controller = Controller::curr();
try {
$form->saveInto($this->record);
@ -371,7 +372,6 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
$this->gridField->getList()->add($this->record);
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
$controller = Controller::curr();
$responseNegotiator = new PjaxResponseNegotiator(array(
'CurrentForm' => function() use(&$form) {
return $form->forTemplate();
@ -398,10 +398,16 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
if($new_record) {
return Controller::curr()->redirect($this->Link());
} else {
} elseif($this->gridField->getList()->byId($this->record->ID)) {
// Return new view, as we can't do a "virtual redirect" via the CMS Ajax
// to the same URL (it assumes that its content is already current, and doesn't reload)
return $this->edit(Controller::curr()->getRequest());
} else {
// Changes to the record properties might've excluded the record from
// a filtered list, so return back to the main view if it can't be found
$noActionURL = $controller->removeAction($data['url']);
$controller->getRequest()->addHeader('X-Pjax', 'Content');
return $controller->redirect($noActionURL, 302);
}
}