mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #190 from silverstripe-rebelalliance/numeric
BUG: Fixes #189 default error message being shown
This commit is contained in:
commit
743e7773f7
@ -600,7 +600,9 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
|
|
||||||
if($this->Fields()) {
|
if($this->Fields()) {
|
||||||
foreach($this->Fields() as $field) {
|
foreach($this->Fields() as $field) {
|
||||||
|
if (!in_array($field->ClassName, array('EditableEmailField', 'EditableNumericField'))) {
|
||||||
$messages[$field->Name] = $field->getErrorMessage()->HTML();
|
$messages[$field->Name] = $field->getErrorMessage()->HTML();
|
||||||
|
}
|
||||||
|
|
||||||
if($field->Required) {
|
if($field->Required) {
|
||||||
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
|
$rules[$field->Name] = array_merge(array('required' => true), $field->getValidation());
|
||||||
|
@ -14,6 +14,15 @@ class EditableEmailField extends EditableFormField {
|
|||||||
private static $plural_name = 'Email Fields';
|
private static $plural_name = 'Email Fields';
|
||||||
|
|
||||||
public function getFormField() {
|
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);
|
return new EmailField($this->Name, $this->Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,8 @@ class EditableFormField extends DataObject {
|
|||||||
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
|
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
|
||||||
$standard = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title);
|
$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);
|
return DBField::create_field('Varchar', $errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,18 @@ class EditableNumericField extends EditableTextField {
|
|||||||
$taf = new NumericField($this->Name, $this->Title);
|
$taf = new NumericField($this->Name, $this->Title);
|
||||||
$taf->setRows($this->getSetting('Rows'));
|
$taf->setRows($this->getSetting('Rows'));
|
||||||
$taf->addExtraClass('number');
|
$taf->addExtraClass('number');
|
||||||
return $taf;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$taf = new NumericField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
$taf = new NumericField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
||||||
$taf->addExtraClass('number');
|
$taf->addExtraClass('number');
|
||||||
|
}
|
||||||
|
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;
|
return $taf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user