mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUGFIX: fixed incorrect formatting for jQuery.validate rules. ENHANCEMENT: added getErrorMessage() to ensure consistent error messages. BUGFIX: readded missing custom messages
This commit is contained in:
parent
9bb51b6cea
commit
fb3fb184e1
@ -383,12 +383,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
if(!$field) break;
|
if(!$field) break;
|
||||||
|
|
||||||
// set the error / formatting messages
|
// set the error / formatting messages
|
||||||
$title = strip_tags("'". ($editableField->Title ? $editableField->Title : $editableField->Name) . "'");
|
$field->setCustomValidationMessage($editableField->getErrorMessage());
|
||||||
|
|
||||||
$errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title);
|
|
||||||
$errorMessage = ($editableField->CustomErrorMessage) ? $editableField->CustomErrorMessage : $errorMessage;
|
|
||||||
|
|
||||||
$field->setCustomValidationMessage($errorMessage);
|
|
||||||
|
|
||||||
// set the right title on this field
|
// set the right title on this field
|
||||||
if($right = $editableField->getSetting('RightTitle')) {
|
if($right = $editableField->getSetting('RightTitle')) {
|
||||||
@ -454,11 +449,10 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
|
|
||||||
if($this->Fields()) {
|
if($this->Fields()) {
|
||||||
foreach($this->Fields() as $field) {
|
foreach($this->Fields() as $field) {
|
||||||
|
$messages[$field->Name] = $field->getErrorMessage()->HTML();
|
||||||
|
|
||||||
if($field->Required) {
|
if($field->Required) {
|
||||||
|
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
|
||||||
$validation[$field->Name] = $field->getFormField()->getCustomValidationMessage();
|
|
||||||
$rules[$field->Name] = array_merge(array('required'), $field->getValidation());
|
|
||||||
|
|
||||||
$required->addRequiredField($field->Name);
|
$required->addRequiredField($field->Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -466,8 +460,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
|
|
||||||
// Set the Form Name
|
// Set the Form Name
|
||||||
$rules = $this->array2json($rules);
|
$rules = $this->array2json($rules);
|
||||||
$messages = $this->array2json($validation);
|
$messages = $this->array2json($messages);
|
||||||
|
|
||||||
// set the custom script for this form
|
// set the custom script for this form
|
||||||
Requirements::customScript(<<<JS
|
Requirements::customScript(<<<JS
|
||||||
(function($) {
|
(function($) {
|
||||||
|
@ -406,4 +406,19 @@ class EditableFormField extends DataObject {
|
|||||||
public function getValidation() {
|
public function getValidation() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the error message for this field. Either uses the custom
|
||||||
|
* one (if provided) or the default SilverStripe message
|
||||||
|
*
|
||||||
|
* @return Varchar
|
||||||
|
*/
|
||||||
|
public function getErrorMessage() {
|
||||||
|
$title = strip_tags("'". ($this->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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
|||||||
|
|
||||||
$fields = $controller->getFormFields();
|
$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 <span class=\'required-identifier\'>*</span>');
|
$this->assertEquals($fields->First()->Title(), 'Required Text Field <span class=\'required-identifier\'>*</span>');
|
||||||
|
|
||||||
// test custom right title
|
// test custom right title
|
||||||
|
Loading…
Reference in New Issue
Block a user