mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #245 from 3Dgoo/feature/custom-error-messages-fix
Fixing and adding form field custom error messages code.
This commit is contained in:
commit
96fb8edd66
@ -21,7 +21,18 @@ class EditableCheckbox extends EditableFormField {
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default'));
|
||||
|
||||
$field = CheckboxField::create( $this->Name, $this->Title, $this->getSetting('Default'));
|
||||
|
||||
if ($this->Required) {
|
||||
// Required validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getValueFromData($data) {
|
||||
|
@ -38,9 +38,17 @@ class EditableDateField extends EditableFormField {
|
||||
*/
|
||||
public function getFormField() {
|
||||
$defaultValue = ($this->getSetting('DefaultToToday')) ? date('Y-m-d') : $this->Default;
|
||||
$field = new EditableDateField_FormField( $this->Name, $this->Title, $defaultValue);
|
||||
$field = EditableDateField_FormField::create( $this->Name, $this->Title, $defaultValue);
|
||||
$field->setConfig('showcalendar', true);
|
||||
|
||||
if ($this->Required) {
|
||||
// Required validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,16 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
}
|
||||
}
|
||||
|
||||
return new DropdownField($this->Name, $this->Title, $options);
|
||||
$field = DropdownField::create($this->Name, $this->Title, $options);
|
||||
|
||||
if ($this->Required) {
|
||||
// Required validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
@ -18,16 +18,18 @@ class EditableEmailField extends EditableFormField {
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
|
||||
$field = EmailField::create($this->Name, $this->Title);
|
||||
|
||||
if ($this->Required) {
|
||||
// Required and Email validation can conflict so add the Required validation messages
|
||||
// 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;
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
return new EmailField($this->Name, $this->Title);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ class EditableFileField extends EditableFormField {
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
$field = new FileField($this->Name, $this->Title);
|
||||
$field = FileField::create($this->Name, $this->Title);
|
||||
|
||||
if($this->getSetting('Folder')) {
|
||||
$folder = Folder::get()->byId($this->getSetting('Folder'));
|
||||
@ -42,6 +42,14 @@ class EditableFileField extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->Required) {
|
||||
// Required validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,12 @@ class EditableNumericField extends EditableFormField {
|
||||
$field = new NumericField($this->Name, $this->Title);
|
||||
$field->addExtraClass('number');
|
||||
|
||||
if ($field->Required) {
|
||||
if ($this->Required) {
|
||||
// Required and numeric validation can conflict so add the
|
||||
// required validation messages as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
|
||||
$field->setAttribute('data-rule-required','true');
|
||||
$field->setAttribute('data-msg-required',$errorMessage);
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
|
@ -39,14 +39,26 @@ class EditableTextField extends EditableFormField {
|
||||
* @return TextareaField|TextField
|
||||
*/
|
||||
public function getFormField() {
|
||||
|
||||
$field = NULL;
|
||||
|
||||
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
|
||||
$taf = new TextareaField($this->Name, $this->Title);
|
||||
$taf->setRows($this->getSetting('Rows'));
|
||||
return $taf;
|
||||
$field = TextareaField::create($this->Name, $this->Title);
|
||||
$field->setRows($this->getSetting('Rows'));
|
||||
}
|
||||
else {
|
||||
return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
||||
$field = TextField::create($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
||||
}
|
||||
|
||||
if ($this->Required) {
|
||||
// Required validation can conflict so add the Required validation messages
|
||||
// as input attributes
|
||||
$errorMessage = $this->getErrorMessage()->HTML();
|
||||
$field->setAttribute('data-rule-required', 'true');
|
||||
$field->setAttribute('data-msg-required', $errorMessage);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user