FIX #7787 Handles ajax and normal requests differently when validation fails on gridfields

This commit is contained in:
jean 2012-08-24 11:18:16 +12:00 committed by Ingo Schommer
parent 70b22fa4ca
commit 14759b6ff1

View File

@ -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