Framework  3.9
CurrencyFieldRenderer Class Reference

Field renderer for currency data fields. More...

+ Inheritance diagram for CurrencyFieldRenderer:
+ Collaboration diagram for CurrencyFieldRenderer:

Public Member Functions

 CurrencyFieldRenderer (&$parent)
 
 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...
 
 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...
 
 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...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. 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...
 
 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...
 
 renderSearchScript ($field, $mode)
 FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form. 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...
 
 $disable = false
 alternative to readonly; field can be reenabled thru javascript More...
 
 $onChange = ""
 optional javascript callback on data input change More...
 
 $onKeyUp
 optional javascript callback on key release within field More...
 
 $template = 2
 how to format readonly - 2 decimal places
More...
 
 $size = 20
 size of the text field to be displayed (in characters) 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 currency data fields.

Provides a two decimal place display and some simple numeric validation as default behavior.

Definition at line 44 of file currency_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

CurrencyFieldRenderer::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 130 of file currency_field_renderer.inc.

131  {
132  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
133 
134  if($required)
135  {
136  $this->parent->validator->add(new RequiredCurrencyValidator($field, $label));
137  }
138 
139  }
RequiredCurrencyField Validator.

◆ CurrencyFieldRenderer()

CurrencyFieldRenderer::CurrencyFieldRenderer ( $parent)

Definition at line 55 of file currency_field_renderer.inc.

56  {
57  $this->FieldRenderer($parent);
58  }
FieldRenderer($parent)
Constructor.

◆ format()

CurrencyFieldRenderer::format (   $field)

Definition at line 149 of file currency_field_renderer.inc.

150  {
151  return CurrencyTypeRenderer::format($this->parent->data->get($field), $this->template);
152  }
static format($value, $template="")

◆ preProcess()

CurrencyFieldRenderer::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 120 of file currency_field_renderer.inc.

121  {
122  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field) || array_key_exists($field, $this->parent->hidden)) return "";
123 
124  $value= $_POST[$field];
125  $value = str_replace(",", "", $value);
126  $this->parent->data->set($field, $value);
127  $_POST[$field] = $value;
128  }

◆ renderField()

CurrencyFieldRenderer::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 65 of file currency_field_renderer.inc.

66  {
67  $value = htmlspecialchars($this->parent->data->get($field), ENT_QUOTES, 'UTF-8');
68 
69  $value = floatval($value);
70  // display with commas between thousands
71  $value = $this->format($field);
72  $disable = ($this->disable) ? "disabled='disabled'" : "";
73  $readonly = ($this->static) ? " readonly='readonly'" : "";
74  $allowneg = ($this->allowNegative) ? 1 : 0;
75  $autocomplete = ($this->autocomplete) ? "" : " autocomplete='off' ";
76  $onchange = ($this->onChange) ? "onchange='$this->onChange(this)'" : "";
77  $onKeyUp = ($this->onKeyUp) ? " onkeyup='{$this->onKeyUp}(this)'" : "";
78 
79  $this->_startField($field);
80 
81  echo "$&nbsp;<input id='{$this->parent->id}_{$field}'
82  type='text' name='$field' value='{$value}' $autocomplete onkeypress='return maskInput(event, $allowneg);'
83  $onchange $onKeyUp $disable $readonly size='{$this->size}'/>";
84 
85  $this->_endField($field);
86  }
$onKeyUp
optional javascript callback on key release within field
$allowNegative
Whether user can enter a negative number.
$autocomplete
Whether the browser is allowed to show autocomplete for this field.
$disable
alternative to readonly; field can be reenabled thru javascript
$static
Render the field as a static (readonly) value, that is visible, non-editable and the value is submitt...
$onChange
optional javascript callback on data input change
_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.

◆ renderOnSubmitHandler()

CurrencyFieldRenderer::renderOnSubmitHandler (   $field)

FieldRenderers can override this method to provide any Javascript that must be executed when the form is submitted on the client.

See HTMLFieldRenderer for an example of how this is used.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 141 of file currency_field_renderer.inc.

142  {
143  // JDG 3/2/2011., no js for readonly field
144  if ($this->parent->isReadOnly($field)) return "";
145 
146  echo "\tdocument.id('{$this->parent->id}_{$field}').value = rawNumber(document.id('{$this->parent->id}_{$field}').value);\n";
147  }

◆ renderReadOnly()

CurrencyFieldRenderer::renderReadOnly (   $field)

Definition at line 110 of file currency_field_renderer.inc.

111  {
112  $this->_startField($field);
113 
114  echo "$". $this->format($field);
115 
116  $this->_endField($field);
117  }

◆ renderScript()

CurrencyFieldRenderer::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 60 of file currency_field_renderer.inc.

61  {
62  //TODO: Add Numeric handling script from ICT-in-Education Toolkit
63  }

◆ renderSearchField()

CurrencyFieldRenderer::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 88 of file currency_field_renderer.inc.

89  {
90  if ($mode == "range")
91  {
92  $from = htmlspecialchars($this->parent->params->get($field, "from"), ENT_QUOTES, 'UTF-8');
93  $to = htmlspecialchars($this->parent->params->get($field, "to"), ENT_QUOTES, 'UTF-8');
94 
95  echo "<tr>\n";
96  $this->_printLabel($field);
97  echo "<td>From <input type='text' name='$field:from' value='{$from}' size='20'> to <input type='text' name='$field:to' value='{$to}' size='20'></td>\n";
98  echo "</tr>\n";
99  }
100  else
101  {
102  $value = htmlspecialchars($this->parent->params->get($field, $mode), ENT_QUOTES, 'UTF-8');
103  echo "<tr>\n";
104  $this->_printLabel($field);
105  echo "<td><input type='text' name='$field:$mode' value='{$value}' size='20'></td>\n";
106  echo "</tr>\n";
107  }
108  }
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.

Member Data Documentation

◆ $allowNegative

CurrencyFieldRenderer::$allowNegative = false

Whether user can enter a negative number.

Definition at line 46 of file currency_field_renderer.inc.

◆ $autocomplete

CurrencyFieldRenderer::$autocomplete = true

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

Definition at line 47 of file currency_field_renderer.inc.

◆ $disable

CurrencyFieldRenderer::$disable = false

alternative to readonly; field can be reenabled thru javascript

Definition at line 48 of file currency_field_renderer.inc.

◆ $onChange

CurrencyFieldRenderer::$onChange = ""

optional javascript callback on data input change

Definition at line 49 of file currency_field_renderer.inc.

◆ $onKeyUp

CurrencyFieldRenderer::$onKeyUp

optional javascript callback on key release within field

Definition at line 50 of file currency_field_renderer.inc.

◆ $size

CurrencyFieldRenderer::$size = 20

size of the text field to be displayed (in characters)

Definition at line 52 of file currency_field_renderer.inc.

◆ $static

CurrencyFieldRenderer::$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 53 of file currency_field_renderer.inc.

◆ $template

CurrencyFieldRenderer::$template = 2

how to format readonly - 2 decimal places

Definition at line 51 of file currency_field_renderer.inc.


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