From 0341a8685e0c67196f04a1bac75b2dd47952dc3e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sat, 26 Apr 2008 06:28:20 +0000 Subject: [PATCH] Merged revisions 52797 via svnmerge from http://svn.silverstripe.com/open/modules/cms/branches/govtsecurity ........ r52797 | sminnee | 2008-04-15 22:22:33 +1200 (Tue, 15 Apr 2008) | 1 line Fixed interaction of MemberTableField and member validation ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@53456 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/MemberTableField.php | 29 +++++++++++++++++++++------- javascript/MemberTableField_popup.js | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/code/MemberTableField.php b/code/MemberTableField.php index 602a2561..fdd6da44 100755 --- a/code/MemberTableField.php +++ b/code/MemberTableField.php @@ -116,6 +116,7 @@ class MemberTableField extends ComplexTableField { parent::__construct($controller, $name, $sourceClass, $fieldList); Requirements::javascript('cms/javascript/MemberTableField.js'); + Requirements::javascript("cms/javascript/MemberTableField_popup.js"); // construct the filter and sort if(isset($_REQUEST['MemberOrderByField'])) { @@ -376,22 +377,36 @@ class MemberTableField_Popup extends ComplexTableField_Popup { } $this->saveInto($childObject); - $childObject->write(); - - // custom behaviour for MemberTableField: add member to current group - $childObject->Groups()->add($_REQUEST['GroupID']); + $form = $this->controller->DetailForm($childObject->ID); + + $valid = $childObject->validate(); + if($valid->valid()) { + $childObject->write(); + + // custom behaviour for MemberTableField: add member to current group + $childObject->Groups()->add($_REQUEST['GroupID']); + + } else { + $form->sessionMessage($valid->message(), 'bad'); + } + + // if ajax-call in an iframe, update window if(Director::is_ajax()) { // Newly saved objects need their ID reflected in the reloaded form to avoid double saving - $form = $this->controller->DetailForm($childObject->ID); $form->loadDataFrom($childObject); - FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update'); + + if($valid->valid()) { + FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update'); + } else { + FormResponse::load_form($form->forTemplate(), $form->FormName()); + } + return FormResponse::respond(); } else { Director::redirectBack(); } } - } ?> diff --git a/javascript/MemberTableField_popup.js b/javascript/MemberTableField_popup.js index 552f731b..369126fb 100755 --- a/javascript/MemberTableField_popup.js +++ b/javascript/MemberTableField_popup.js @@ -2,7 +2,7 @@ MemberTableFieldPopupForm = Class.extend("ComplexTableFieldPopupForm"); MemberTableFieldPopupForm.prototype = { initialize: function() { this.ComplexTableFieldPopupForm.initialize(); - + Behaviour.register({ "form#MemberTableField_Popup_DetailForm .Actions input.action": { onclick: this.submitForm.bind(this)