Framework  3.9
StringFieldRenderer Class Reference

Field renderer for string data fields. More...

+ Inheritance diagram for StringFieldRenderer:
+ Collaboration diagram for StringFieldRenderer:

Public Member Functions

 StringFieldRenderer (&$parent)
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 renderField ($field, $readonly=false)
 
 renderReadOnly ($field)
 
 renderSearchField ($field, $mode="equal")
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. More...
 
 format ($field)
 
- Public Member Functions inherited from FieldRenderer
 FieldRenderer ($parent)
 Constructor. More...
 
 _printLabel ($field, $colspan=1, $styles="", $annotation="")
 Internal method to generate the HTML for the field label. More...
 
 _getLabel ($field, $addSuffix=true)
 
 _startField ($field, $styles="")
 Internal method to generate the starting HTML for the field (including the label) More...
 
 _endField ($field)
 Internal method to generate the closing HTML for the field. More...
 
 addSearchValidatorsToForm ($field, $mode, $required=false)
 For SearchForm, the validator field needs to match the name tag in the form which is in the format field:mode. More...
 
 formatName ($item, $name)
 Formats the given DataItem based on the supplied format string. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderSearchScript ($field, $mode)
 FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form. More...
 
 renderOnSubmitHandler ($field)
 FieldRenderers can override this method to provide any Javascript that must be executed when the form is submitted on the client. More...
 
 preProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs prior to the saving of the parent form's target object to the database. More...
 
 postProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs after the parent form's target object has been saved to the database. More...
 

Public Attributes

 $size = 50
 
 $limit = 0
 optional - restricts users from entering character count over limit More...
 
 $autocomplete = true
 default is true. Set to false to disable autocompletion More...
 
 $onChange = ""
 optional (javascript) callback on data input change More...
 
 $disable = false
 alternative to readonly; field can be reenabled thru javascript More...
 
 $password = false
 Render the field as a password field (masked characters) More...
 
 $template = ""
 StringTypeRenderer template for readonly format (e.g., "prettify") More...
 
 $confirm = false
 Render a second field for the user to confirm their entry (for email addresses, etc) More...
 
 $width = ""
 Optionally specify a CSS width for the field. More...
 
 $CSSclass = ""
 Optionally specify a CSS class for the field. More...
 
 $numeric = false
 Restrict to numeric input. More...
 
 $onKeyPress = null
 Optional key press javascript callback. Note that if $limit is set, it will override this. More...
 
 $placeholder = null
 Placeholder text to display when field is empty. More...
 
- Public Attributes inherited from FieldRenderer
 $parent = null
 
 $labelSuffix = ""
 
 $colspan = 1
 
 $annotateBefore = false
 
 $annotateNextLine = true
 
 $hideLabel = false
 
 $onPreProcess = null
 callback hook for processing prior to saving the form's data object - individual renderers may override with custom processing More...
 
 $onPostProcess = null
 callback hook for processing after saving the form's data object - individual renderers may override with custom processing More...
 

Detailed Description

Field renderer for string data fields.

Renders as a single-line text field.

size: the length of the input field

limit: maximum number of characters user may enter

autocomplete: whether field may attempt autocompletion based on the user-entered data string.

onChange: script-defined callback function to call when user edits the field (script is called on field exit, not for each key entered)

disable: alternative to readonly; field can be reenabled thru javascript

Example: to disable input in a field, add the following line of code to your calling script: $form->getRenderer("foo")->disable = true;

Definition at line 61 of file string_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

StringFieldRenderer::addValidatorsToForm (   $field,
  $required = false 
)

This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer.

Fields that need custom validation or a custom required validator should override this function.

Parameters
string$fieldthe field name
boolean$required- whether the field is required

Reimplemented from FieldRenderer.

Reimplemented in URLFieldRenderer, and SignatureFieldRenderer.

Definition at line 198 of file string_field_renderer.inc.

199  {
200  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
201  $confirm = "confirm_$field";
202  $confirmLabel = "Confirm $label";
203 
204  if($required)
205  $this->parent->validator->add(new RequiredValidator($field, $label));
206 
207  if ($this->confirm)
208  {
209  $this->parent->validator->add(new MatchValidator($field, $label, $confirm, $confirmLabel));
210  }
211  }
Tests whether two fields contain the same value.
Definition: validation.inc:814
RequiredField Validator.
Definition: validation.inc:76
$confirm
Render a second field for the user to confirm their entry (for email addresses, etc)

◆ format()

StringFieldRenderer::format (   $field)

Definition at line 214 of file string_field_renderer.inc.

215  {
216  return StringTypeRenderer::format($this->parent->data->get($field), $this->template);
217  }
static format($value, $template="")

◆ renderField()

StringFieldRenderer::renderField (   $field,
  $readonly = false 
)

Definition at line 112 of file string_field_renderer.inc.

113  {
114  $this->_startField($field);
115 
116  if ($this->limit)
117  {
118  echo "<div>";
119  $onkeypress = " onkeyup='{$field}_keyup(event);'";
120  }
121 
122  if (!$onkeypress && $this->onKeyPress)
123  {
124  $onkeypress = " onkeyup='return {$this->onKeyPress}(this);'";
125  }
126 
127  $autocomplete = (!$this->autocomplete) ? "autocomplete='off' " : "";
128  $onchange = ($this->onChange) ? "onchange='$this->onChange(this)'" : "";
129  $disable = ($this->disable) ? "disabled='disabled'" : "";
130  $inputType = (!$this->password) ? "text" : "password";
131  $style = ($this->width) ? " style='width: {$this->width}'" : "";
132  $class = ($this->CSSclass) ? "class='{$this->CSSclass}'" : "";
133  $value = (!$this->password) ? htmlspecialchars($this->parent->data->get($field), ENT_QUOTES, 'UTF-8') : "";
134 
135  $keyPress = $this->numeric ? "onkeypress='return maskInput(event, false);'" : "";
136 
137  $placeholder = ($this->placeholder) ? " placeholder='".htmlSafe($this->placeholder)."'" : "";
138 
139  echo "<input id='{$this->parent->id}_{$field}' type='$inputType' name='$field' $placeholder $keyPress $onchange $autocomplete $class $style value='$value' size='{$this->size}' $disable $onkeypress/>";
140 
141  if ($this->limit)
142  {
143  echo "</div>";
144  }
145  $this->_endField($field);
146 
147  if ($this->confirm)
148  {
149  $confirm = "confirm_$field";
150  $this->_startField($confirm);
151 
152  $autocomplete = (!$this->autocomplete) ? "autocomplete='off' " : "";
153  $disable = ($this->disable) ? "disabled='disabled'" : "";
154  $inputType = (!$this->password) ? "text" : "password";
155  echo "<input id='{$this->parent->id}_{$confirm}' type='$inputType' name='$confirm' $autocomplete value='".htmlspecialchars($this->parent->data->get($field), ENT_QUOTES, 'UTF-8')."' size='{$this->size}' $disable/>";
156 
157  $this->_endField($field);
158  }
159  }
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.
$disable
alternative to readonly; field can be reenabled thru javascript
$autocomplete
default is true. Set to false to disable autocompletion
$placeholder
Placeholder text to display when field is empty.
$width
Optionally specify a CSS width for the field.
$password
Render the field as a password field (masked characters)
$CSSclass
Optionally specify a CSS class for the field.
$onChange
optional (javascript) callback on data input change

◆ renderReadOnly()

StringFieldRenderer::renderReadOnly (   $field)

Reimplemented in SignatureFieldRenderer, and URLFieldRenderer.

Definition at line 161 of file string_field_renderer.inc.

162  {
163  $this->_startField($field);
164 
165  if (!$this->parent->readOnlyForm)
166  {
167  echo "<input id='{$this->parent->id}_{$field}' type='hidden' name='$field' value='".htmlspecialchars($this->parent->data->get($field), ENT_QUOTES, 'UTF-8')."'/>";
168  }
169 
170  echo $this->format($field);
171 
172  $this->_endField($field);
173  }

◆ renderScript()

StringFieldRenderer::renderScript (   $field)

FieldRenderers can override this method to provide any Javascript that their control requires for an edit form.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 82 of file string_field_renderer.inc.

83  {
84  if ($this->limit)
85  {
86 ?>
87 <script type='text/javascript'>
88 /* <![CDATA[ */
89  function <?echo $field ?>_keyup(event)
90  {
91  var form = document.id('<?echo $this->parent->id ?>');
92 
93  var ctrl = form['<?echo $field ?>'];
94  var len = ctrl.value.length;
95  if (len >= <?echo $this->limit?>)
96  {
97  ctrl.value = ctrl.value.substring(0, <?echo $this->limit ?>);
98  len = <?echo $this->limit ?>;
99  }
100 
101  var count = document.getElementById('<?echo $field ?>_length');
102 
103  // JDG 2/1/10 must check count to fix IE7 bug
104  if(count)
105  count.innerHTML = len;
106  }
107 </script>
108 <?
109  }
110  }

◆ renderSearchField()

StringFieldRenderer::renderSearchField (   $field,
  $mode = "equal" 
)

FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 175 of file string_field_renderer.inc.

176  {
177  if ($mode == "range")
178  {
179  $from = htmlspecialchars($this->parent->params->get($field, "from"), ENT_QUOTES, 'UTF-8');
180  $to = htmlspecialchars($this->parent->params->get($field, "to"), ENT_QUOTES, 'UTF-8');
181 
182  echo "<tr>\n";
183  $this->_printLabel($field);
184  echo "<td>From <input type='text' id='$field' name='$field:from' value='{$from}' size='25'> to <input type='text' name='$field:to' value='{$to}' size='25'></td>\n";
185  echo "</tr>\n";
186  }
187  else
188  {
189  $value = htmlspecialchars($this->parent->params->get($field, $mode), ENT_QUOTES, 'UTF-8');
190  $this->_startField($field);
191  $placeholder = ($this->placeholder) ? " placeholder='".htmlSafe($this->placeholder)."'" : "";
192  echo "<input type='text' id='$field' name='$field:$mode' {$placeholder} value='{$value}' size='{$this->size}' >\n";
193  $this->_endField($field);
194  }
195  }
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.

◆ StringFieldRenderer()

StringFieldRenderer::StringFieldRenderer ( $parent)

Definition at line 77 of file string_field_renderer.inc.

78  {
79  $this->FieldRenderer($parent);
80  }
FieldRenderer($parent)
Constructor.

Member Data Documentation

◆ $autocomplete

StringFieldRenderer::$autocomplete = true

default is true. Set to false to disable autocompletion

Definition at line 65 of file string_field_renderer.inc.

◆ $confirm

StringFieldRenderer::$confirm = false

Render a second field for the user to confirm their entry (for email addresses, etc)

Definition at line 70 of file string_field_renderer.inc.

◆ $CSSclass

StringFieldRenderer::$CSSclass = ""

Optionally specify a CSS class for the field.

Definition at line 72 of file string_field_renderer.inc.

◆ $disable

StringFieldRenderer::$disable = false

alternative to readonly; field can be reenabled thru javascript

Definition at line 67 of file string_field_renderer.inc.

◆ $limit

StringFieldRenderer::$limit = 0

optional - restricts users from entering character count over limit

Definition at line 64 of file string_field_renderer.inc.

◆ $numeric

StringFieldRenderer::$numeric = false

Restrict to numeric input.

Definition at line 73 of file string_field_renderer.inc.

◆ $onChange

StringFieldRenderer::$onChange = ""

optional (javascript) callback on data input change

Definition at line 66 of file string_field_renderer.inc.

◆ $onKeyPress

StringFieldRenderer::$onKeyPress = null

Optional key press javascript callback. Note that if $limit is set, it will override this.

Definition at line 74 of file string_field_renderer.inc.

◆ $password

StringFieldRenderer::$password = false

Render the field as a password field (masked characters)

Definition at line 68 of file string_field_renderer.inc.

◆ $placeholder

StringFieldRenderer::$placeholder = null

Placeholder text to display when field is empty.

Definition at line 75 of file string_field_renderer.inc.

◆ $size

StringFieldRenderer::$size = 50

Definition at line 63 of file string_field_renderer.inc.

◆ $template

StringFieldRenderer::$template = ""

StringTypeRenderer template for readonly format (e.g., "prettify")

Definition at line 69 of file string_field_renderer.inc.

◆ $width

StringFieldRenderer::$width = ""

Optionally specify a CSS width for the field.

Definition at line 71 of file string_field_renderer.inc.


The documentation for this class was generated from the following file: