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;
|
||||
|
||||
// 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(<<<JS
|
||||
(function($) {
|
||||
|
@ -406,4 +406,19 @@ class EditableFormField extends DataObject {
|
||||
public function getValidation() {
|
||||
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();
|
||||
|
||||
$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>');
|
||||
|
||||
// test custom right title
|
||||
|
Loading…
Reference in New Issue
Block a user