From c3b3e1cc7a654e891e66c2d769f07669dc188095 Mon Sep 17 00:00:00 2001 From: David Craig Date: Fri, 11 Dec 2015 14:50:12 +1300 Subject: [PATCH] Add placeholder to Numeric and Email fields --- .../editableformfields/EditableEmailField.php | 22 +++++++++++++++++++ .../EditableNumericField.php | 21 +++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/code/model/editableformfields/EditableEmailField.php b/code/model/editableformfields/EditableEmailField.php index 58153cc..17590ba 100755 --- a/code/model/editableformfields/EditableEmailField.php +++ b/code/model/editableformfields/EditableEmailField.php @@ -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); + } } } \ No newline at end of file diff --git a/code/model/editableformfields/EditableNumericField.php b/code/model/editableformfields/EditableNumericField.php index 29b6adc..ea874da 100755 --- a/code/model/editableformfields/EditableNumericField.php +++ b/code/model/editableformfields/EditableNumericField.php @@ -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); + } } }