From 2d9c833de5a091874049f1e751ac1dc5c3ed3333 Mon Sep 17 00:00:00 2001 From: Hayden Smith Date: Mon, 11 Aug 2008 01:50:24 +0000 Subject: [PATCH] Merged [47028]: Encountered a problem with Form::formHtmlContent not always including javascript validation, so added a call to includeJavascriptValidation on the validator in Form::formHtmlContent. Also modified Validator to notify the form that the client-side validation JavaScript has already been included. This way it isn't included twice. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60311 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/Form.php | 14 +++++++++++++- forms/Validator.php | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/forms/Form.php b/forms/Form.php index ca48a0dc5..5174dfc76 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -63,6 +63,14 @@ class Form extends RequestHandlingData { protected $messageType; protected $security = true; + + /** + * HACK This is a temporary hack to allow multiple calls to includeJavascriptValidation on + * the validator (if one is present). + * + * @var boolean + */ + public $jsValidationIncluded = false; /** * Create a new form, with the given fields an action buttons. @@ -412,7 +420,7 @@ class Form extends RequestHandlingData { // Forms shouldn't be cached, cos their error messages won't be shown HTTP::set_cache_age(0); - if($this->validator) $this->validator->includeJavascriptValidation(); + if($this->validator && !$this->jsValidationIncluded) $this->validator->includeJavascriptValidation(); if($this->target) $target = " target=\"".$this->target."\""; else $target = ""; @@ -832,6 +840,10 @@ class Form extends RequestHandlingData { * the attributes of the form. These fields can be used to send the form to Ajax. */ function formHtmlContent() { + // Call FormAttributes to force inclusion of custom client-side validation of fields + // because it won't be included by the template + if($this->validator && !$this->jsValidationIncluded) $this->validator->includeJavascriptValidation(); + $this->IncludeFormTag = false; $content = $this->forTemplate(); $this->IncludeFormTag = true; diff --git a/forms/Validator.php b/forms/Validator.php index 44394f955..79d1bffb1 100755 --- a/forms/Validator.php +++ b/forms/Validator.php @@ -122,6 +122,8 @@ Behaviour.apply('#$formID'); JS; Requirements::customScript($js); + // HACK Notify the form that the validators client-side validation code has already been included + if($this->form) $this->form->jsValidationIncluded = true; } /**