Framework  3.9
NumberFieldRenderer Class Reference

Field renderer for numeric data fields. More...

+ Inheritance diagram for NumberFieldRenderer:
+ Collaboration diagram for NumberFieldRenderer:

Public Member Functions

 NumberFieldRenderer (&$parent, $field=null)
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. More...
 
 setUnits ($units, $position)
 Sets the displayed units and their position. More...
 
 setRange ($min, $max, $step=1)
 Specifies that the field should be rendered with a "number" HTML control with the supplied range and step. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderReadOnly ($field)
 
 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...
 
- 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...
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. 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...
 
 renderSearchField ($field, $mode)
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field 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...
 
 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

 $allowNegative = false
 Whether user can enter a negative number. More...
 
 $autocomplete = true
 Whether the browser is allowed to show autocomplete for this field. More...
 
 $size = 15
 Size of the displayed control in characters. More...
 
 $onKeyUp
 optional javascript callback function for key up events More...
 
 $disable = false
 alternative to readonly; field can be reenabled or set thru javascript More...
 
 $onChange = ""
 optional javascript callback on data input change More...
 
 $units = ""
 units text to display More...
 
 $unitsPosition = ""
 whether to display units before or after the control More...
 
 $blankZero = false
 Leave field blank if value is zero. More...
 
 $control = "text"
 The HTML control type to use when rendering. This gets set to "number" if a range is specified. More...
 
 $static = false
 Render the field as a static (readonly) value, that is visible, non-editable and the value is submitted when the form is submitted. 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 numeric data fields.

Renders as a text box with numerically masked input (user cannot enter non-numeric characters).

Allow negative defaults to false; if a field should allow negative numbers, calling script should add the following line: $form->getRenderer("field_name")->allowNegative = true;

Definition at line 48 of file number_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

NumberFieldRenderer::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.

Definition at line 72 of file number_field_renderer.inc.

73  {
74  parent::addValidatorsToForm($field);
75 
76  if ($this->control == "number")
77  {
78  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
79 
80  $this->parent->validator->add(new RangeValidator($field, $label, $this->min, $this->max));
81  }
82  }
RangeValidator class.

◆ NumberFieldRenderer()

NumberFieldRenderer::NumberFieldRenderer ( $parent,
  $field = null 
)

Definition at line 63 of file number_field_renderer.inc.

64  {
65  $this->FieldRenderer($parent);
66  if ($field && !$parent->data->hasField($field))
67  {
68  $parent->add($this, $field);
69  }
70  }
FieldRenderer($parent)
Constructor.

◆ preProcess()

NumberFieldRenderer::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.

For example, the FileUploadFieldRenderer overrides this method to process the uploading of the file and then store the location in the associated field in the target object.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 168 of file number_field_renderer.inc.

169  {
170  $current = $this->parent->data->get($field);
171 
172  $value = str_replace(",", "", $current);
173 
174  if($this->allowNegative)
175  {
176  if(substr($value, 0,1) == '-')
177  $value = '-' . str_replace("-", "", $value);
178  else
179  $value = str_replace("-", "", $value);
180  }
181  $this->parent->data->$field = $value;
182  }

◆ renderField()

NumberFieldRenderer::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 113 of file number_field_renderer.inc.

114  {
115  $this->_startField($field);
116 
117  $readonly = ($this->static) ? " readonly='readonly'" : "";
118  $disable = ($this->disable) ? "disabled='disabled'" : "";
119  $onKeyUp = ($this->onKeyUp) ? " onkeyup='{$this->onKeyUp}(this)'" : "";
120  // JDG - maskInput function doesn't recognize boolean var value
121  // translate to 0 or 1
122  $allowneg = ($this->allowNegative) ? 1 : 0;
123  $autocomplete = ($this->autocomplete) ? "" : " autocomplete='off' ";
124  $onchange = ($this->onChange) ? "onchange='{$this->onChange}(this)'" : "";
125 
126  if ($this->unitsPosition == "before") echo $this->units." ";
127 
128  $value = $this->parent->data->get($field);
129  if ($value == 0 && $this->blankZero)
130  {
131  $value = "";
132  }
133 
134  if ($this->control == "number")
135  {
136  $control = "number";
137  $rangeAttrs = " min='{$this->min}' max='{$this->max}' step='{$this->step}'";
138  }
139  else
140  {
141  $control = "text";
142  $rangeAttrs = "";
143  }
144  echo "<input id='{$this->parent->id}_$field' type='{$control}' style='width: auto' name='$field'
145  value='".$value."' $rangeAttrs $autocomplete
146  size='{$this->size}' onkeypress='return maskInput(event, $allowneg);' $disable $static $onchange $onKeyUp/>";
147 
148  if ($this->unitsPosition == "after") echo " ".$this->units;
149 
150  $this->_endField($field);
151  }
_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.
$control
The HTML control type to use when rendering. This gets set to "number" if a range is specified.
$allowNegative
Whether user can enter a negative number.
$onChange
optional javascript callback on data input change
$static
Render the field as a static (readonly) value, that is visible, non-editable and the value is submitt...
$onKeyUp
optional javascript callback function for key up events
$autocomplete
Whether the browser is allowed to show autocomplete for this field.
$disable
alternative to readonly; field can be reenabled or set thru javascript

◆ renderReadOnly()

NumberFieldRenderer::renderReadOnly (   $field)

Definition at line 153 of file number_field_renderer.inc.

154  {
155  $this->_startField($field);
156 
157  if ($this->unitsPosition == "before") echo $this->units." ";
158 
159  echo $this->parent->data->get($field);
160 
161  if ($this->unitsPosition == "after") echo " ".$this->units;
162 
163  $this->_endField($field);
164  }

◆ setRange()

NumberFieldRenderer::setRange (   $min,
  $max,
  $step = 1 
)

Specifies that the field should be rendered with a "number" HTML control with the supplied range and step.

Parameters
mixed$minthe minimum value for the field
mixed$maxthe maximum value for the field
mixed$stepthe amount to step when the spinner up/down buttons are clicked

Definition at line 103 of file number_field_renderer.inc.

104  {
105  $this->min = min($max, $min);
106  $this->max = max($max, $min);
107  $this->step = $step;
108  $this->control = "number";
109 
110  return $this;
111  }

◆ setUnits()

NumberFieldRenderer::setUnits (   $units,
  $position 
)

Sets the displayed units and their position.

Parameters
string$units
string$position

Definition at line 89 of file number_field_renderer.inc.

90  {
91  $this->units = $units;
92  $this->unitsPosition = $position;
93  return $this;
94  }
$units
units text to display

Member Data Documentation

◆ $allowNegative

NumberFieldRenderer::$allowNegative = false

Whether user can enter a negative number.

Definition at line 51 of file number_field_renderer.inc.

◆ $autocomplete

NumberFieldRenderer::$autocomplete = true

Whether the browser is allowed to show autocomplete for this field.

Definition at line 52 of file number_field_renderer.inc.

◆ $blankZero

NumberFieldRenderer::$blankZero = false

Leave field blank if value is zero.

Definition at line 59 of file number_field_renderer.inc.

◆ $control

NumberFieldRenderer::$control = "text"

The HTML control type to use when rendering. This gets set to "number" if a range is specified.

Definition at line 60 of file number_field_renderer.inc.

◆ $disable

NumberFieldRenderer::$disable = false

alternative to readonly; field can be reenabled or set thru javascript

Definition at line 55 of file number_field_renderer.inc.

◆ $onChange

NumberFieldRenderer::$onChange = ""

optional javascript callback on data input change

Definition at line 56 of file number_field_renderer.inc.

◆ $onKeyUp

NumberFieldRenderer::$onKeyUp

optional javascript callback function for key up events

Definition at line 54 of file number_field_renderer.inc.

◆ $size

NumberFieldRenderer::$size = 15

Size of the displayed control in characters.

Definition at line 53 of file number_field_renderer.inc.

◆ $static

NumberFieldRenderer::$static = false

Render the field as a static (readonly) value, that is visible, non-editable and the value is submitted when the form is submitted.

Definition at line 61 of file number_field_renderer.inc.

◆ $units

NumberFieldRenderer::$units = ""

units text to display

Definition at line 57 of file number_field_renderer.inc.

◆ $unitsPosition

NumberFieldRenderer::$unitsPosition = ""

whether to display units before or after the control

Definition at line 58 of file number_field_renderer.inc.


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