From 14759b6ff12a16422d63c1c70bd4cb36f3132739 Mon Sep 17 00:00:00 2001 From: jean Date: Fri, 24 Aug 2012 11:18:16 +1200 Subject: [PATCH] FIX #7787 Handles ajax and normal requests differently when validation fails on gridfields --- forms/gridfield/GridFieldDetailForm.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/forms/gridfield/GridFieldDetailForm.php b/forms/gridfield/GridFieldDetailForm.php index b5fa8acda..63771be61 100644 --- a/forms/gridfield/GridFieldDetailForm.php +++ b/forms/gridfield/GridFieldDetailForm.php @@ -371,7 +371,19 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler { $this->gridField->getList()->add($this->record); } catch(ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); - return Controller::curr()->redirectBack(); + $controller = Controller::curr(); + $responseNegotiator = new PjaxResponseNegotiator(array( + 'CurrentForm' => function() use(&$form) { + return $form->forTemplate(); + }, + 'default' => function() use(&$controller) { + return $controller->redirectBack(); + } + )); + if($controller->getRequest()->isAjax()){ + $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm'); + } + return $responseNegotiator->respond($controller->getRequest()); } // TODO Save this item into the given relationship