Permalink
Browse files

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

…n fails on gridfields
  • Loading branch information...
1 parent 70b22fa commit 14759b6ff12a16422d63c1c70bd4cb36f3132739 @patbolo patbolo committed with chillu Aug 23, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 forms/gridfield/GridFieldDetailForm.php
@@ -371,7 +371,19 @@ function doSave($data, $form) {
$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

0 comments on commit 14759b6

Please sign in to comment.