From c20a500cbd163d3259d52aeadeb24f2e0550909c Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 7 Feb 2014 11:09:03 -0600 Subject: [PATCH] forms: Add placeholder and promts Priority field and custom list fields have a prompt value (shows up only for drop-down widget). And the short and long answer fields have a placeholder configuration item. --- include/class.dynamic_forms.php | 8 +++++++- include/class.forms.php | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 427420a82..c1bedad65 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -926,7 +926,13 @@ class SelectionField extends FormField { 'id'=>1, 'label'=>'Widget', 'required'=>false, 'default'=>false, 'choices'=>array(false=>'Drop Down', true=>'Typeahead'), - 'hint'=>'Typeahead will work better for large lists')), + 'hint'=>'Typeahead will work better for large lists' + )), + 'prompt' => new TextboxField(array( + 'id'=>2, 'label'=>'Prompt', 'required'=>false, 'default'=>'', + 'hint'=>'Text shown in the drop-down select before a value is selected', + 'configuration'=>array('size'=>40, 'length'=>40), + )), ); } diff --git a/include/class.forms.php b/include/class.forms.php index 58e250d49..dd4d66239 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -493,6 +493,11 @@ class TextboxField extends FormField { 'id'=>4, 'label'=>'Validation Error', 'default'=>'', 'configuration'=>array('size'=>40, 'length'=>60), 'hint'=>'Message shown to user if the input does not match the validator')), + 'placeholder' => new TextboxField(array( + 'id'=>5, 'label'=>'Placeholder', 'required'=>false, 'default'=>'', + 'hint'=>'Text shown in before any input from the user', + 'configuration'=>array('size'=>40, 'length'=>40), + )), ); } @@ -540,6 +545,11 @@ class TextareaField extends FormField { 'html' => new BooleanField(array( 'id'=>4, 'label'=>'HTML', 'required'=>false, 'default'=>true, 'configuration'=>array('desc'=>'Allow HTML input in this box'))), + 'placeholder' => new TextboxField(array( + 'id'=>5, 'label'=>'Placeholder', 'required'=>false, 'default'=>'', + 'hint'=>'Text shown in before any input from the user', + 'configuration'=>array('size'=>40, 'length'=>40), + )), ); } @@ -858,7 +868,13 @@ class PriorityField extends ChoiceField { } function getConfigurationOptions() { - return array(); + return array( + 'prompt' => new TextboxField(array( + 'id'=>2, 'label'=>'Prompt', 'required'=>false, 'default'=>'', + 'hint'=>'Text shown in the drop-down select before a value is selected', + 'configuration'=>array('size'=>40, 'length'=>40), + )), + ); } } FormField::addFieldTypes('Built-in Lists', function() { @@ -907,8 +923,9 @@ class TextboxWidget extends Widget { ?> <span style="display:inline-block"> <input type="text" id="<?php echo $this->name; ?>" - <?php echo $size . " " . $maxlength; ?> - <?php echo $classes.' '.$autocomplete; ?> + <?php echo $size . " " . $maxlength + .' '.$classes.' '.$autocomplete + .' placeholder="'.$config['placeholder'].'"'; ?> name="<?php echo $this->name; ?>" value="<?php echo Format::htmlchars($this->value); ?>"/> </span> @@ -930,7 +947,8 @@ class TextareaWidget extends Widget { $class = 'class="richtext no-bar small"'; ?> <span style="display:inline-block;width:100%"> - <textarea <?php echo $rows." ".$cols." ".$maxlength." ".$class; ?> + <textarea <?php echo $rows." ".$cols." ".$maxlength." ".$class + .' placeholder="'.$config['placeholder'].'"'; ?> name="<?php echo $this->name; ?>"><?php echo Format::htmlchars($this->value); ?></textarea> -- GitLab