From fb3fb184e13e82ab01ec4567763264f365f61cc0 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 19 Dec 2010 01:19:19 +0000 Subject: [PATCH] BUGFIX: fixed incorrect formatting for jQuery.validate rules. ENHANCEMENT: added getErrorMessage() to ensure consistent error messages. BUGFIX: readded missing custom messages --- code/UserDefinedForm.php | 18 ++++++------------ code/editor/EditableFormField.php | 15 +++++++++++++++ tests/UserDefinedFormControllerTest.php | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/code/UserDefinedForm.php b/code/UserDefinedForm.php index 72db187..ea42097 100755 --- a/code/UserDefinedForm.php +++ b/code/UserDefinedForm.php @@ -383,12 +383,7 @@ class UserDefinedForm_Controller extends Page_Controller { if(!$field) break; // set the error / formatting messages - $title = strip_tags("'". ($editableField->Title ? $editableField->Title : $editableField->Name) . "'"); - - $errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title); - $errorMessage = ($editableField->CustomErrorMessage) ? $editableField->CustomErrorMessage : $errorMessage; - - $field->setCustomValidationMessage($errorMessage); + $field->setCustomValidationMessage($editableField->getErrorMessage()); // set the right title on this field if($right = $editableField->getSetting('RightTitle')) { @@ -454,11 +449,10 @@ class UserDefinedForm_Controller extends Page_Controller { if($this->Fields()) { foreach($this->Fields() as $field) { + $messages[$field->Name] = $field->getErrorMessage()->HTML(); + if($field->Required) { - - $validation[$field->Name] = $field->getFormField()->getCustomValidationMessage(); - $rules[$field->Name] = array_merge(array('required'), $field->getValidation()); - + $rules[$field->Name] = array_merge(array('required' => true), $field->getValidation()); $required->addRequiredField($field->Name); } } @@ -466,8 +460,8 @@ class UserDefinedForm_Controller extends Page_Controller { // Set the Form Name $rules = $this->array2json($rules); - $messages = $this->array2json($validation); - + $messages = $this->array2json($messages); + // set the custom script for this form Requirements::customScript(<<Title ? $this->Title : $this->Name) . "'"); + $standard = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title); + + $errorMessage = ($this->CustomErrorMessage) ? $this->CustomErrorMessage : $standard; + + return DBField::create('Varchar', $errorMessage); + } } diff --git a/tests/UserDefinedFormControllerTest.php b/tests/UserDefinedFormControllerTest.php index 98b9e08..8233697 100644 --- a/tests/UserDefinedFormControllerTest.php +++ b/tests/UserDefinedFormControllerTest.php @@ -101,7 +101,7 @@ class UserDefinedFormControllerTest extends FunctionalTest { $fields = $controller->getFormFields(); - $this->assertEquals($fields->First()->getCustomValidationMessage(), 'Custom Error Message'); + $this->assertEquals($fields->First()->getCustomValidationMessage()->getValue(), 'Custom Error Message'); $this->assertEquals($fields->First()->Title(), 'Required Text Field *'); // test custom right title