Framework  3.9
ZipCodeFieldRenderer Class Reference

Field renderer for zipcode data fields. More...

+ Inheritance diagram for ZipCodeFieldRenderer:
+ Collaboration diagram for ZipCodeFieldRenderer:

Public Member Functions

 ZipCodeFieldRenderer (&$form)
 
 setInternational ($label="Postal Code")
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. 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="equal")
 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...
 
 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

 $autocomplete = true
 
 $onChange = ""
 
 $disable = false
 
 $includePlus4 = true
 
 $international = false
 
 $internationalLabel = "Postal Code"
 
- 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 zipcode data fields.

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 57 of file zipcode_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

ZipCodeFieldRenderer::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 76 of file zipcode_field_renderer.inc.

77  {
78  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
79 
80  if($required)
81  {
82  if (!$this->international)
83  {
84  $expr = $this->includePlus4 ? "^\\d{5}(?:-\\d{4})?$" : "^\\d{5}$";
85 
86  $this->parent->regexp($field, $expr, "Please supply a valid zip code.");
87  }
88 
89  $this->parent->validator->add(new RequiredValidator($field, $label));
90  }
91  }
RequiredField Validator.
Definition: validation.inc:76

◆ renderField()

ZipCodeFieldRenderer::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 119 of file zipcode_field_renderer.inc.

120  {
121  $this->_startField($field);
122 
123 
124  if (!$this->international)
125  {
126  $size = $this->includePlus4 ? 10 : 5;
127  $onkeyup = " onkeyup='{$field}_keyup(event);'";
128  $onkeypress=" onkeypress='return maskInput(event)'";
129  }
130  else
131  {
132  $size = 12;
133  }
134 
135  $autocomplete = (!$this->autocomplete) ? "autocomplete='off' " : "";
136  $onchange = ($this->onChange) ? "onchange='$this->onChange(this)'" : "";
137  $disable = ($this->disable) ? "disabled='disabled'" : "";
138 
139  echo "<input id='{$this->parent->id}_{$field}'
140  type='text' style='width: auto' name='$field' $onchange $autocomplete
141  value='".htmlspecialchars($this->parent->data->get($field), ENT_QUOTES, 'UTF-8')."'
142  size='{$size}' $disable $onkeypress $onkeyup/>";
143  $this->_endField($field);
144  }
_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.

◆ renderReadOnly()

ZipCodeFieldRenderer::renderReadOnly (   $field)

Definition at line 147 of file zipcode_field_renderer.inc.

148  {
149  $this->_startField($field);
150 
151  echo $this->parent->data->get($field);
152 
153  $this->_endField($field);
154  }

◆ renderScript()

ZipCodeFieldRenderer::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 93 of file zipcode_field_renderer.inc.

94  {
95  $size = $this->includePlus4 ? 10 : 5;
96 ?>
97 <script type='text/javascript'>
98 /* <![CDATA[ */
99  function <?echo $field ?>_keyup(event)
100  {
101  var ctrl = document.id('<? echo "{$this->parent->id}_$field" ?>');
102  var len = ctrl.value.length;
103  if (len >= <?echo $size?>)
104  {
105  ctrl.value = ctrl.value.substring(0, <?echo $size?>);
106  len = <?echo $size?>;
107  }
108 
109  var count = ctrl.length;
110 
111  // JDG 2/1/10 must check count to fix IE7 bug
112  if(count)
113  count.innerHTML = len;
114  }
115 </script>
116 <?
117  }

◆ renderSearchField()

ZipCodeFieldRenderer::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 156 of file zipcode_field_renderer.inc.

157  {
158  $this->_startField($field);
159 
160  $onkeyup = " onkeyup='{$field}_keyup(event);'";
161  $onkeypress=" onkeypress='return maskInput(event)'";
162 
163  if ($mode == "range")
164  {
165  $from = htmlspecialchars($this->parent->params->get($field, "from"), ENT_QUOTES, 'UTF-8');
166  $to = htmlspecialchars($this->parent->params->get($field, "to"), ENT_QUOTES, 'UTF-8');
167 
168  echo "From <input type='text' id='$field' name='$field:from' value='{$from}' size='10'$onkeypress$onkeyup> to <input type='text' name='$field:to' value='{$to}' size='10'$onkeypress$onkeyup>";
169  }
170  else
171  {
172  $value = htmlspecialchars($this->parent->params->get($field, $mode), ENT_QUOTES, 'UTF-8');
173  echo "<input type='text' id='$field' name='$field:$mode' value='{$value}' size='10'$onkeypress$onkeyup>";
174  }
175 
176  $this->_endField($field);
177 
178  }

◆ setInternational()

ZipCodeFieldRenderer::setInternational (   $label = "Postal Code")

Definition at line 71 of file zipcode_field_renderer.inc.

72  {
73  $this->international = true;
74  }

◆ ZipCodeFieldRenderer()

ZipCodeFieldRenderer::ZipCodeFieldRenderer ( $form)

Definition at line 66 of file zipcode_field_renderer.inc.

67  {
68  $this->FieldRenderer($form);
69  }
FieldRenderer($parent)
Constructor.

Member Data Documentation

◆ $autocomplete

ZipCodeFieldRenderer::$autocomplete = true

Definition at line 59 of file zipcode_field_renderer.inc.

◆ $disable

ZipCodeFieldRenderer::$disable = false

Definition at line 61 of file zipcode_field_renderer.inc.

◆ $includePlus4

ZipCodeFieldRenderer::$includePlus4 = true

Definition at line 62 of file zipcode_field_renderer.inc.

◆ $international

ZipCodeFieldRenderer::$international = false

Definition at line 63 of file zipcode_field_renderer.inc.

◆ $internationalLabel

ZipCodeFieldRenderer::$internationalLabel = "Postal Code"

Definition at line 64 of file zipcode_field_renderer.inc.

◆ $onChange

ZipCodeFieldRenderer::$onChange = ""

Definition at line 60 of file zipcode_field_renderer.inc.


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