ENHANCEMENT Support for DataObject->validate() and ValidationException catching in ModelAdmin->doSave()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@77855 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-05-26 06:01:36 +00:00
parent a1b04f1018
commit 40a2c3bb7c

View File

@ -921,7 +921,13 @@ class ModelAdmin_RecordController extends Controller {
*/
function doSave($data, $form, $request) {
$form->saveInto($this->currentRecord);
$this->currentRecord->write();
try {
$this->currentRecord->write();
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
}
// Behaviour switched on ajax.
if(Director::is_ajax()) {