Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 52263e6a5f593b72d059d778cb916a6eb550418b 1 parent d24ea5e
Ingo Schommer authored September 02, 2012

Showing 1 changed file with 8 additions and 2 deletions. Show diff stats Hide diff stats

  1. 10  forms/gridfield/GridFieldDetailForm.php
10  forms/gridfield/GridFieldDetailForm.php
@@ -364,6 +364,7 @@ protected function getToplevelController() {
364 364
 
365 365
 	function doSave($data, $form) {
366 366
 		$new_record = $this->record->ID == 0;
  367
+		$controller = Controller::curr();
367 368
 
368 369
 		try {
369 370
 			$form->saveInto($this->record);
@@ -371,7 +372,6 @@ function doSave($data, $form) {
371 372
 			$this->gridField->getList()->add($this->record);
372 373
 		} catch(ValidationException $e) {
373 374
 			$form->sessionMessage($e->getResult()->message(), 'bad');
374  
-			$controller = Controller::curr();
375 375
 			$responseNegotiator = new PjaxResponseNegotiator(array(
376 376
 				'CurrentForm' => function() use(&$form) {
377 377
 					return $form->forTemplate();
@@ -398,10 +398,16 @@ function doSave($data, $form) {
398 398
 
399 399
 		if($new_record) {
400 400
 			return Controller::curr()->redirect($this->Link());
401  
-		} else {
  401
+		} elseif($this->gridField->getList()->byId($this->record->ID)) {
402 402
 			// Return new view, as we can't do a "virtual redirect" via the CMS Ajax
403 403
 			// to the same URL (it assumes that its content is already current, and doesn't reload)
404 404
 			return $this->edit(Controller::curr()->getRequest());
  405
+		} else {
  406
+			// Changes to the record properties might've excluded the record from
  407
+			// a filtered list, so return back to the main view if it can't be found
  408
+			$noActionURL = $controller->removeAction($data['url']);
  409
+			$controller->getRequest()->addHeader('X-Pjax', 'Content'); 
  410
+			return $controller->redirect($noActionURL, 302); 
405 411
 		}
406 412
 	}
407 413
 

0 notes on commit 52263e6

Please sign in to comment.
Something went wrong with that request. Please try again.