Merge pull request #408 from flashbackzoo/pull/add-placeholder

Add placeholder to Numeric and Email fields
This commit is contained in:
Damian Mooyman 2015-12-15 10:04:12 +13:00
commit eb872c6391
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 $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() { public function getSetsOwnError() {
return true; return true;
} }
@ -36,5 +54,9 @@ class EditableEmailField extends EditableFormField {
parent::updateFormField($field); parent::updateFormField($field);
$field->setAttribute('data-rule-email', true); $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( private static $db = array(
'MinValue' => 'Int', 'MinValue' => 'Int',
'MaxValue' => 'Int' 'MaxValue' => 'Int',
'Placeholder' => 'Varchar(255)'
); );
public function getSetsOwnError() { public function getSetsOwnError() {
return true; 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 * @return NumericField
*/ */
@ -64,5 +79,9 @@ class EditableNumericField extends EditableFormField {
if($this->MaxValue) { if($this->MaxValue) {
$field->setAttribute('data-rule-max', $this->MaxValue); $field->setAttribute('data-rule-max', $this->MaxValue);
} }
if($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} }
} }