Framework  3.9
TextFieldRenderer Class Reference

Field renderer for text data fields. More...

+ Inheritance diagram for TextFieldRenderer:
+ Collaboration diagram for TextFieldRenderer:

Public Member Functions

 TextFieldRenderer (&$parent)
 Constructs a new TextFieldRenderer object. More...
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderReadOnly ($field)
 
 renderSearchField ($field, $mode="like")
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
- 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...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. 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...
 
 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

 $rows = 4
 The number of rows to display in the text area. More...
 
 $columns = 60
 The number of columns to display in the text area. More...
 
 $colspan = 2
 The number of table columns to display across. More...
 
 $limit = 0
 Optional limit on the number of characters allowed to be entered (enforced by Javascript). Note - make sure you have at least this many characters in your database field! More...
 
 $disable = false
 Alternative to readonly; field can be reenabled thru javascript. More...
 
 $encoding = "UTF-8"
 Overrides the default text encoding. More...
 
 $style
 Inline styles for the text area element. 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 text data fields.

Renders as a multi-line text box area, with optional javascript character count display.

Example for $form= new autoform($document)

$fieldname=$form->getRenderer('field_name'); $fieldname->rows=3;

Definition at line 50 of file text_field_renderer.inc.

Member Function Documentation

◆ renderField()

TextFieldRenderer::renderField (   $field)

FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 101 of file text_field_renderer.inc.

102  {
103  $this->_startField($field);
104 
105  if ($this->limit)
106  {
107  echo "<div>";
108  $onkeypress = " onkeyup='{$field}_keyup(event);'";
109  }
110  $disable = ($this->disable) ? "disabled='disabled'" : "";
111 
112  if ($this->style) $style = "style='{$this->style}'";
113 
114  $placeholder = ($this->placeholder) ? " placeholder='".htmlSafe($this->placeholder)."'" : "";
115 
116  echo "<textarea id='{$this->parent->id}_$field' name='$field' rows='{$this->rows}' cols='{$this->columns}'{$placeholder} $style $disable $onkeypress>";
117  echo cleanHTMLTags($this->parent->data->get($field));
118  //echo htmlspecialchars($this->parent->data->get($field), ENT_QUOTES | ENT_IGNORE, $this->encoding);
119  echo "</textarea>";
120 
121  if ($this->limit)
122  {
123  echo "<br /><div class='character_count' style='clear: left; float: right'><span id='{$field}_length'>";
124  echo strlen(trim($this->parent->data->get($field)));
125  echo "</span> of $this->limit characters</div></div>";
126  }
127 
128  $this->_endField($field);
129  }
_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.
$style
Inline styles for the text area element.
$placeholder
Placeholder text to display when field is empty.
$disable
Alternative to readonly; field can be reenabled thru javascript.
cleanHTMLTags($str)
Definition: functions.inc:456

◆ renderReadOnly()

TextFieldRenderer::renderReadOnly (   $field)

Definition at line 131 of file text_field_renderer.inc.

132  {
133  $this->_startField($field);
134 
135  $text = htmlspecialchars($this->parent->data->get($field), ENT_QUOTES | ENT_IGNORE, 'UTF-8');
136  $text = str_replace("\n", "<br/>", $text);
137  echo $text;
138 
139  $this->_endField($field);
140  }

◆ renderScript()

TextFieldRenderer::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 75 of file text_field_renderer.inc.

76  {
77  if ($this->limit)
78  {
79 ?>
80 <script type='text/javascript'>
81 /* <![CDATA[ */
82  function <?echo $field ?>_keyup(event)
83  {
84  var form = document.getElementById('<?echo $this->parent->id ?>');
85  var ctrl = form['<?echo $field ?>'];
86  var len = ctrl.value.length;
87  if (len >= <?echo $this->limit?>)
88  {
89  ctrl.value = ctrl.value.substring(0, <?echo $this->limit ?>);
90  len = <?echo $this->limit ?>;
91  }
92 
93  var count = document.getElementById('<?echo $field ?>_length');
94  count.innerHTML = len;
95  }
96 </script>
97 <?
98  }
99  }

◆ renderSearchField()

TextFieldRenderer::renderSearchField (   $field,
  $mode = "like" 
)

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 142 of file text_field_renderer.inc.

143  {
144  // AJG - Override default colspan when rendering in a search form
145  $this->colspan = 1;
146 
147  if ($mode == "range")
148  {
149  $from = htmlspecialchars($this->parent->params->get($field, "from"), ENT_QUOTES, 'UTF-8');
150  $to = htmlspecialchars($this->parent->params->get($field, "to"), ENT_QUOTES, 'UTF-8');
151 
152  echo "<tr>\n";
153  $this->_printLabel($field);
154  echo "<td>From <input type='text' name='$field:from' value='{$from}' size='25'> to <input type='text' name='$field:to' value='{$to}' size='25'></td>\n";
155  echo "</tr>\n";
156  }
157  else
158  {
159  $value = htmlspecialchars($this->parent->params->get($field, $mode), ENT_QUOTES, 'UTF-8');
160  echo "<tr>\n";
161  $this->_printLabel($field);
162 
163  $placeholder = ($this->placeholder) ? " placeholder='".htmlSafe($this->placeholder)."'" : "";
164  echo "<td><input type='text' name='$field:$mode' value='{$value}'{$placeholder} size='50'></td>\n";
165  echo "</tr>\n";
166  }
167  }
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.

◆ TextFieldRenderer()

TextFieldRenderer::TextFieldRenderer ( $parent)

Constructs a new TextFieldRenderer object.

Parameters
AutoForm$parentthe parent AutoForm

Definition at line 65 of file text_field_renderer.inc.

66  {
67  global $config;
68 
69  $this->FieldRenderer($parent);
70 
71  $this->annotateBefore = true;
72  if ($config["encoding"]) $this->encoding = $config["encoding"];
73  }
FieldRenderer($parent)
Constructor.

Member Data Documentation

◆ $colspan

TextFieldRenderer::$colspan = 2

The number of table columns to display across.

Definition at line 54 of file text_field_renderer.inc.

◆ $columns

TextFieldRenderer::$columns = 60

The number of columns to display in the text area.

Definition at line 53 of file text_field_renderer.inc.

◆ $disable

TextFieldRenderer::$disable = false

Alternative to readonly; field can be reenabled thru javascript.

Definition at line 56 of file text_field_renderer.inc.

◆ $encoding

TextFieldRenderer::$encoding = "UTF-8"

Overrides the default text encoding.

Definition at line 57 of file text_field_renderer.inc.

◆ $limit

TextFieldRenderer::$limit = 0

Optional limit on the number of characters allowed to be entered (enforced by Javascript). Note - make sure you have at least this many characters in your database field!

Definition at line 55 of file text_field_renderer.inc.

◆ $placeholder

TextFieldRenderer::$placeholder = null

Placeholder text to display when field is empty.

Definition at line 59 of file text_field_renderer.inc.

◆ $rows

TextFieldRenderer::$rows = 4

The number of rows to display in the text area.

Definition at line 52 of file text_field_renderer.inc.

◆ $style

TextFieldRenderer::$style

Inline styles for the text area element.

Definition at line 58 of file text_field_renderer.inc.


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