38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
66 if ($field && !
$parent->data->hasField($field))
74 parent::addValidatorsToForm($field);
76 if ($this->control ==
"number")
78 $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
80 $this->parent->validator->add(
new RangeValidator($field, $label, $this->min, $this->max));
92 $this->unitsPosition = $position;
105 $this->min = min($max, $min);
106 $this->max = max($max, $min);
108 $this->control =
"number";
124 $onchange = (
$this->onChange) ?
"onchange='{$this->onChange}(this)'" :
"";
126 if ($this->unitsPosition ==
"before") echo $this->units.
" ";
128 $value = $this->parent->data->get($field);
129 if ($value == 0 && $this->blankZero)
134 if ($this->control ==
"number")
137 $rangeAttrs =
" min='{$this->min}' max='{$this->max}' step='{$this->step}'";
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/>";
148 if ($this->unitsPosition ==
"after") echo
" ".$this->units;
157 if ($this->unitsPosition ==
"before") echo $this->units.
" ";
159 echo $this->parent->data->get($field);
161 if ($this->unitsPosition ==
"after") echo
" ".$this->units;
170 $current = $this->parent->data->get($field);
172 $value = str_replace(
",",
"", $current);
174 if($this->allowNegative)
176 if(substr($value, 0,1) ==
'-')
177 $value =
'-' . str_replace(
"-",
"", $value);
179 $value = str_replace(
"-",
"", $value);
181 $this->parent->data->$field = $value;
FieldRenderer is the abstract base class for all FieldRenderers.
_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.
FieldRenderer($parent)
Constructor.
Field renderer for numeric data fields.
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
$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
$units
units text to display
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
$size
Size of the displayed control in characters.
$unitsPosition
whether to display units before or after the control
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...
$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.
$blankZero
Leave field blank if value is zero.
NumberFieldRenderer(&$parent, $field=null)
setUnits($units, $position)
Sets the displayed units and their position.
$disable
alternative to readonly; field can be reenabled or set thru javascript
setRange($min, $max, $step=1)
Specifies that the field should be rendered with a "number" HTML control with the supplied range and ...