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
This commit is contained in:
Hayden Smith 2008-08-11 01:50:24 +00:00
parent 11e4621f66
commit 2d9c833de5
2 changed files with 15 additions and 1 deletions

View File

@ -64,6 +64,14 @@ class Form extends RequestHandlingData {
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;

View File

@ -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;
}
/**