mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUG: Fixes #189 default error message being shown
This commit is contained in:
parent
12ccea0d48
commit
85c1f52c45
@ -600,8 +600,6 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
|
||||
if($this->Fields()) {
|
||||
foreach($this->Fields() as $field) {
|
||||
$messages[$field->Name] = $field->getErrorMessage()->HTML();
|
||||
|
||||
if($field->Required) {
|
||||
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
|
||||
$required->addRequiredField($field->Name);
|
||||
|
@ -14,6 +14,15 @@ class EditableEmailField extends EditableFormField {
|
||||
private static $plural_name = 'Email Fields';
|
||||
|
||||
public function getFormField() {
|
||||
if ($this->Required) {
|
||||
// Required and Email validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field = new EmailField($this->Name, $this->Title);
|
||||
$field->setAttribute('data-rule-required','true');
|
||||
$field->setAttribute('data-msg-required',$errorMessage);
|
||||
return $field;
|
||||
}
|
||||
return new EmailField($this->Name, $this->Title);
|
||||
}
|
||||
|
||||
|
@ -499,7 +499,8 @@ class EditableFormField extends DataObject {
|
||||
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
|
||||
$standard = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title);
|
||||
|
||||
$errorMessage = ($this->CustomErrorMessage) ? $this->CustomErrorMessage : $standard;
|
||||
// only use CustomErrorMessage if it has a non empty value
|
||||
$errorMessage = (!empty($this->CustomErrorMessage)) ? $this->CustomErrorMessage : $standard;
|
||||
|
||||
return DBField::create_field('Varchar', $errorMessage);
|
||||
}
|
||||
|
@ -22,12 +22,18 @@ class EditableNumericField extends EditableTextField {
|
||||
$taf = new NumericField($this->Name, $this->Title);
|
||||
$taf->setRows($this->getSetting('Rows'));
|
||||
$taf->addExtraClass('number');
|
||||
return $taf;
|
||||
}
|
||||
else {
|
||||
$taf = new NumericField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
||||
$taf->addExtraClass('number');
|
||||
return $taf;
|
||||
}
|
||||
if ($this->Required) {
|
||||
// Required and numeric validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$taf->setAttribute('data-rule-required','true');
|
||||
$taf->setAttribute('data-msg-required',$errorMessage);
|
||||
}
|
||||
return $taf;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user