From be985afd2467ca40ef574428977285b8a1de6d40 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 18 Mar 2009 13:03:52 +0000 Subject: [PATCH] API CHANGE Using RequiredFields or DataObject->getCMSValidator() in CMSMain->getEditForm(), which means all pages in the CMS will have validation enabled, e.g. for date fields. This is necessary to avoid a global disabling of javascript validation through Validator::set_javascript_validation_handler('none') breaking the CMS, which relies on javascript responses through Form->validate() and the FormResponse class (without specifically requesting them through HTTP Accept headers). See #3386 and #2915 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@73336 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index a3366306..8f32a277 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -426,7 +426,27 @@ JS; } } } - $form = new Form($this, "EditForm", $fields, $actions); + + // Add a default or custom validator. + // @todo Currently the default Validator.js implementation + // adds javascript to the document body, meaning it won't + // be included properly if the associated fields are loaded + // through ajax. This means only serverside validation + // will kick in for pages+validation loaded through ajax. + // This will be solved by using less obtrusive javascript validation + // in the future, see http://open.silverstripe.com/ticket/2915 and http://open.silverstripe.com/ticket/3386 + if($record->hasMethod('getCMSValidator')) { + $validator = $record->getCMSValidator(); + } else { + $validator = new RequiredFields(); + } + + // The clientside (mainly LeftAndMain*.js) rely on ajax responses + // which can be evaluated as javascript, hence we need + // to override any global changes to the validation handler. + $validator->setJavascriptValidationHandler('prototype'); + + $form = new Form($this, "EditForm", $fields, $actions, $validator); $form->loadDataFrom($record); $form->disableDefaultAction();