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:
Will Rossiter 2014-12-22 15:05:53 +13:00
commit 96fb8edd66
7 changed files with 68 additions and 18 deletions

View File

@ -21,7 +21,18 @@ class EditableCheckbox extends EditableFormField {
} }
public function getFormField() { 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) { public function getValueFromData($data) {

View File

@ -38,9 +38,17 @@ class EditableDateField extends EditableFormField {
*/ */
public function getFormField() { public function getFormField() {
$defaultValue = ($this->getSetting('DefaultToToday')) ? date('Y-m-d') : $this->Default; $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); $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; return $field;
} }
} }

View File

@ -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;
} }
} }

View File

@ -18,16 +18,18 @@ class EditableEmailField extends EditableFormField {
} }
public function getFormField() { public function getFormField() {
$field = EmailField::create($this->Name, $this->Title);
if ($this->Required) { 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 // as input attributes
$errorMessage = $this->getErrorMessage()->HTML(); $errorMessage = $this->getErrorMessage()->HTML();
$field = new EmailField($this->Name, $this->Title); $field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-rule-required','true'); $field->setAttribute('data-msg-required', $errorMessage);
$field->setAttribute('data-msg-required',$errorMessage);
return $field;
} }
return new EmailField($this->Name, $this->Title);
return $field;
} }
/** /**

View File

@ -30,7 +30,7 @@ class EditableFileField extends EditableFormField {
} }
public function getFormField() { public function getFormField() {
$field = new FileField($this->Name, $this->Title); $field = FileField::create($this->Name, $this->Title);
if($this->getSetting('Folder')) { if($this->getSetting('Folder')) {
$folder = Folder::get()->byId($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; return $field;
} }

View File

@ -24,13 +24,12 @@ class EditableNumericField extends EditableFormField {
$field = new NumericField($this->Name, $this->Title); $field = new NumericField($this->Name, $this->Title);
$field->addExtraClass('number'); $field->addExtraClass('number');
if ($field->Required) { if ($this->Required) {
// Required and numeric validation can conflict so add the // Required and numeric validation can conflict so add the
// required validation messages as input attributes // required validation messages as input attributes
$errorMessage = $this->getErrorMessage()->HTML(); $errorMessage = $this->getErrorMessage()->HTML();
$field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-rule-required','true'); $field->setAttribute('data-msg-required', $errorMessage);
$field->setAttribute('data-msg-required',$errorMessage);
} }
return $field; return $field;

View File

@ -39,14 +39,26 @@ class EditableTextField extends EditableFormField {
* @return TextareaField|TextField * @return TextareaField|TextField
*/ */
public function getFormField() { public function getFormField() {
$field = NULL;
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) { if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
$taf = new TextareaField($this->Name, $this->Title); $field = TextareaField::create($this->Name, $this->Title);
$taf->setRows($this->getSetting('Rows')); $field->setRows($this->getSetting('Rows'));
return $taf;
} }
else { 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;
} }
/** /**