Add placeholder to Numeric and Email fields

This commit is contained in:
David Craig 2015-12-11 14:50:12 +13:00
parent da2aba8229
commit c3b3e1cc7a
2 changed files with 42 additions and 1 deletions

View File

@ -13,6 +13,24 @@ class EditableEmailField extends EditableFormField {
private static $plural_name = 'Email Fields';
private static $db = array(
'Placeholder' => 'Varchar(255)'
);
public function getCMSFields() {
$this->beforeUpdateCMSFields(function($fields) {
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
});
return parent::getCMSFields();
}
public function getSetsOwnError() {
return true;
}
@ -36,5 +54,9 @@ class EditableEmailField extends EditableFormField {
parent::updateFormField($field);
$field->setAttribute('data-rule-email', true);
if($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
}
}

View File

@ -15,13 +15,28 @@ class EditableNumericField extends EditableFormField {
private static $db = array(
'MinValue' => 'Int',
'MaxValue' => 'Int'
'MaxValue' => 'Int',
'Placeholder' => 'Varchar(255)'
);
public function getSetsOwnError() {
return true;
}
public function getCMSFields() {
$this->beforeUpdateCMSFields(function($fields) {
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
});
return parent::getCMSFields();
}
/**
* @return NumericField
*/
@ -64,5 +79,9 @@ class EditableNumericField extends EditableFormField {
if($this->MaxValue) {
$field->setAttribute('data-rule-max', $this->MaxValue);
}
if($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
}
}