Skip to content
This repository
Browse code

FIX #7787 Handles ajax and normal requests differently when validatio…

…n fails on gridfields
  • Loading branch information...
commit 14759b6ff12a16422d63c1c70bd4cb36f3132739 1 parent 70b22fa
Jean-Fabien authored August 24, 2012 chillu committed August 29, 2012

Showing 1 changed file with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. 14  forms/gridfield/GridFieldDetailForm.php
14  forms/gridfield/GridFieldDetailForm.php
@@ -371,7 +371,19 @@ function doSave($data, $form) {
371 371
 			$this->gridField->getList()->add($this->record);
372 372
 		} catch(ValidationException $e) {
373 373
 			$form->sessionMessage($e->getResult()->message(), 'bad');
374  
-			return Controller::curr()->redirectBack();
  374
+			$controller = Controller::curr();
  375
+			$responseNegotiator = new PjaxResponseNegotiator(array(
  376
+				'CurrentForm' => function() use(&$form) {
  377
+					return $form->forTemplate();
  378
+				},
  379
+				'default' => function() use(&$controller) {
  380
+					return $controller->redirectBack();
  381
+				}
  382
+			));
  383
+			if($controller->getRequest()->isAjax()){
  384
+				$controller->getRequest()->addHeader('X-Pjax', 'CurrentForm');
  385
+			}
  386
+			return $responseNegotiator->respond($controller->getRequest());
375 387
 		}
376 388
 
377 389
 		// TODO Save this item into the given relationship

0 notes on commit 14759b6

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