ENHANCEMENT Using try/catch blocks in ComplexTableField->saveComplexTableField() to catch any ValidationExceptions and terminate the saving process

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@78255 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-06-02 06:12:10 +00:00
parent c542ec0de9
commit da758f9f6e

View File

@ -202,7 +202,6 @@ class ComplexTableField extends TableListField {
$this->pageSize = 10;
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
}
/**
@ -625,7 +624,13 @@ JS;
$className = $this->sourceClass();
$childData = new $className();
$form->saveInto($childData);
$childData->write();
try {
$childData->write();
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Director::redirectBack();
}
// Save the many many relationship if it's available
if(isset($data['ctf']['manyManyRelation'])) {
@ -796,7 +801,13 @@ class ComplexTableField_ItemRequest extends RequestHandler {
function saveComplexTableField($data, $form, $request) {
$dataObject = $this->dataObj();
$form->saveInto($dataObject);
$dataObject->write();
try {
$dataObject->write();
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Director::redirectBack();
}
// Save the many many relationship if it's available
if(isset($data['ctf']['manyManyRelation'])) {