From 2133e610480e839c573558f2fb9daf098b443c78 Mon Sep 17 00:00:00 2001 From: Tal Shiri Date: Thu, 22 May 2014 09:12:54 -0700 Subject: [PATCH] Added placeholder support to custom text fields Summary: placeholder text is pretty useful. Test Plan: placeholder text is pretty useful. also fully supports not breaking everything. Reviewers: chad, #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9223 --- src/docs/user/configuration/custom_fields.diviner | 2 ++ .../standard/PhabricatorStandardCustomField.php | 7 ++++++- src/view/form/control/AphrontFormTextControl.php | 13 +++++++++++++ webroot/rsrc/css/phui/phui-form-view.css | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/docs/user/configuration/custom_fields.diviner b/src/docs/user/configuration/custom_fields.diviner index ce7bd22b32..cfde51569e 100644 --- a/src/docs/user/configuration/custom_fields.diviner +++ b/src/docs/user/configuration/custom_fields.diviner @@ -103,6 +103,8 @@ When defining custom fields using a configuration option like type. See below. - **instructions**: Optional block of remarkup text which will appear above the control when rendered on the edit view. + - **placeholder**: A placeholder text that appears on text boxes. Only + supported in text, int and remarkup fields (optional). The `strings` value supports different strings per control type. They are: diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php index 0a7ef680fd..8f9394589c 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -215,13 +215,18 @@ abstract class PhabricatorStandardCustomField return $this->getFieldConfigValue('instructions'); } + public function getPlaceholder() { + return $this->getFieldConfigValue('placeholder', null); + } + public function renderEditControl(array $handles) { return id(new AphrontFormTextControl()) ->setName($this->getFieldKey()) ->setCaption($this->getCaption()) ->setValue($this->getFieldValue()) ->setError($this->getFieldError()) - ->setLabel($this->getFieldName()); + ->setLabel($this->getFieldName()) + ->setPlaceholder($this->getPlaceholder()); } public function newStorageObject() { diff --git a/src/view/form/control/AphrontFormTextControl.php b/src/view/form/control/AphrontFormTextControl.php index 78078fd949..a507b0e74e 100644 --- a/src/view/form/control/AphrontFormTextControl.php +++ b/src/view/form/control/AphrontFormTextControl.php @@ -4,18 +4,30 @@ final class AphrontFormTextControl extends AphrontFormControl { private $disableAutocomplete; private $sigil; + private $placeholder; public function setDisableAutocomplete($disable) { $this->disableAutocomplete = $disable; return $this; } + private function getDisableAutocomplete() { return $this->disableAutocomplete; } + public function getPlaceholder() { + return $this->placeholder; + } + + public function setPlaceholder($placeholder) { + $this->placeholder = $placeholder; + return $this; + } + public function getSigil() { return $this->sigil; } + public function setSigil($sigil) { $this->sigil = $sigil; return $this; @@ -36,6 +48,7 @@ final class AphrontFormTextControl extends AphrontFormControl { 'autocomplete' => $this->getDisableAutocomplete() ? 'off' : null, 'id' => $this->getID(), 'sigil' => $this->getSigil(), + 'placeholder' => $this->getPlaceholder() )); } diff --git a/webroot/rsrc/css/phui/phui-form-view.css b/webroot/rsrc/css/phui/phui-form-view.css index 52f266174a..10d7cfdae5 100644 --- a/webroot/rsrc/css/phui/phui-form-view.css +++ b/webroot/rsrc/css/phui/phui-form-view.css @@ -49,6 +49,20 @@ width: 100%; } +.aphront-form-input *::-webkit-input-placeholder { + color:{$greytext} !important; +} + +.aphront-form-input *::-moz-placeholder { + color:{$greytext} !important; + opacity: 1; /* Firefox nudges the opacity to 0.4 */ +} + +.aphront-form-input *:-ms-input-placeholder { + color:{$greytext} !important; +} + + .aphront-form-error { width: 18%; float: right;