Skip to content

Commit

Permalink
BUG Gridfield fails when save changes filter criteria (fixes #7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Sep 2, 2012
1 parent d24ea5e commit 52263e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions forms/gridfield/GridFieldDetailForm.php
Expand Up @@ -364,14 +364,14 @@ protected function getToplevelController() {

function doSave($data, $form) {
$new_record = $this->record->ID == 0;
$controller = Controller::curr();

try {
$form->saveInto($this->record);
$this->record->write();
$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();
Expand All @@ -398,10 +398,16 @@ function doSave($data, $form) {

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);
}
}

Expand Down

0 comments on commit 52263e6

Please sign in to comment.