Framework  3.9
FieldRenderer Class Reference

FieldRenderer is the abstract base class for all FieldRenderers. More...

+ Inheritance diagram for FieldRenderer:

Public Member Functions

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

 $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

FieldRenderer is the abstract base class for all FieldRenderers.

FieldRenderers are used by the AutoForm class to provide the editing/display controls for the fields in the form.

The FieldRenderer class is itself just the base class from which specific FieldRenderers can be derived. FieldRenderers can be specialized based on the data type of the field they are renderering, or may provide more specific UI, such as dropdown lists providing options or related objects in the database, etc.

Applications can also provide their own custom FieldRenderers to provide specific behavior within a form when the default behavior is not suitable.

Definition at line 55 of file field_renderers.inc.

Member Function Documentation

◆ _endField()

FieldRenderer::_endField (   $field)

Internal method to generate the closing HTML for the field.

Parameters
string$fieldthe field name

Definition at line 116 of file field_renderers.inc.

117  {
118  $this->parent->layout->endField($field, $this);
119  }

◆ _getLabel()

FieldRenderer::_getLabel (   $field,
  $addSuffix = true 
)

Definition at line 95 of file field_renderers.inc.

96  {
97  return $this->parent->layout->getLabel($field, $this, $addSuffix);
98  }

◆ _printLabel()

FieldRenderer::_printLabel (   $field,
  $colspan = 1,
  $styles = "",
  $annotation = "" 
)

Internal method to generate the HTML for the field label.

Parameters
string$fieldthe field name
int$colspanthe number of columns to span
string$stylesoptional special styles that need to be applied
string$annotationannotation text for the field

Definition at line 90 of file field_renderers.inc.

91  {
92  $this->parent->layout->printLabel($field, $this, $styles, $annotation);
93  }

◆ _startField()

FieldRenderer::_startField (   $field,
  $styles = "" 
)

Internal method to generate the starting HTML for the field (including the label)

Parameters
string$fieldthe field name
unknown_type$stylesoptional special styles that need to be applied

Reimplemented in FilterFieldRenderer\RadioButtonFilterFieldRenderer, and FilterFieldRenderer\CheckListFilterFieldRenderer.

Definition at line 106 of file field_renderers.inc.

107  {
108  $this->parent->layout->startField($field, $this, $styles);
109  }

◆ addSearchValidatorsToForm()

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

For mode "range" add an additional validator for the "to" field.

Parameters
String$field
String$mode
Boolean$required

Definition at line 152 of file field_renderers.inc.

153  {
154  if(!isset($this->label))
155  {
156  $this->label = $this->parent->prettifyFieldName($field);
157  }
158 
159  if($mode != "range")
160  {
161  $this->addValidatorsToForm("{$field}:{$mode}", $required);
162  }
163  else
164  {
165  // Store the from label and reset it back into the renderer
166  // after calling addValidatorsToForm.
167  $fromLabel = $this->label;
168  $this->addValidatorsToForm("{$field}:from", $required);
169  $this->label = preg_replace("/between|from/i", "To", $fromLabel);
170  $this->addValidatorsToForm("{$field}:to", $required);
171  $this->label = $fromLabel;
172  }
173  }
addValidatorsToForm($field, $required=false)
This method is called by the AutoForm to add any default input validators that are required by the Fi...

◆ addValidatorsToForm()

FieldRenderer::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 in ZipCodeFieldRenderer, URLFieldRenderer, ToggleFieldRenderer, TimeFieldRenderer, StringFieldRenderer, SignatureFieldRenderer, RadioButtonFieldRenderer, PushButtonFieldRenderer, PushButtonCheckListFieldRenderer, PhoneNumberFieldRenderer, PasswordFieldRenderer, NumberFieldRenderer, DateTimeFieldRenderer, DateOfBirthFieldRenderer, DateFieldRenderer, CurrencyFieldRenderer, CreditCardNumberFieldRenderer, and BooleanFieldRenderer.

Definition at line 133 of file field_renderers.inc.

134  {
135  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
136 
137  if($required)
138  $this->parent->validator->add(new RequiredValidator($field, $label));
139  }
RequiredField Validator.
Definition: validation.inc:76

◆ FieldRenderer()

FieldRenderer::FieldRenderer (   $parent)

Constructor.

Parameters
AutoForm$parent- the parent form for this FieldRenderer object
Returns
FieldRenderer

Definition at line 72 of file field_renderers.inc.

73  {
74  global $auto_form_defaults;
75  $this->parent =& $parent;
76  if (isset($auto_form_defaults["labelSuffix"]))
77  {
78  $this->labelSuffix = $auto_form_defaults["labelSuffix"];
79  }
80  }

◆ formatName()

FieldRenderer::formatName (   $item,
  $name 
)

Formats the given DataItem based on the supplied format string.

This can either be a string containing the name of the field to return, or it can be a more complex format string using the syntax provided by DataItem::format().

For class callback formatting, use the syntax: "{MyClassName::myFormattingFunction}"

Parameters
DataItem$itemthe item to format
string$namethe name field or format string, as described above.
Returns
string the formatted text

Definition at line 187 of file field_renderers.inc.

188  {
189  if (strpos($name, "{") !== false)
190  {
191  $name = $item->format($name);
192  }
193  else
194  {
195  $name = $item->$name;
196  }
197  return $name;
198  }

◆ postProcess()

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

For example, the CrossReferenceSelectFieldRenderer overrides this method to update crossference tables based on the user's selection.

Parameters
string$field

Reimplemented in TreeSelectFieldRenderer, TableSelectFieldRenderer, RelatedItemCheckListFieldRenderer, OptionCrossReferenceFieldRenderer, and DataListFieldRenderer.

Definition at line 281 of file field_renderers.inc.

282  {
283  if ($this->onPostProcess != null)
284  {
285  $callback = $this->onPostProcess;
286  call_user_func($callback, $this, $field);
287  }
288  }
$onPostProcess
callback hook for processing after saving the form's data object - individual renderers may override ...

◆ preProcess()

FieldRenderer::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 in TreeSelectFieldRenderer, TimeFieldRenderer, SubSelectFieldRenderer, SignatureFieldRenderer, RelatedImageSelectFieldRenderer, PhoneNumberFieldRenderer, PasswordFieldRenderer, NumberFieldRenderer, FileUploadFieldRenderer, DateTimeFieldRenderer, DateOfBirthFieldRenderer, DataListFieldRenderer, CurrencyFieldRenderer, CompoundSelectFieldRenderer, and CheckListFieldRenderer.

Definition at line 265 of file field_renderers.inc.

266  {
267  if ($this->onPreProcess != null)
268  {
269  $callback = $this->onPreProcess;
270  call_user_func($callback, $this, $field);
271  }
272  }
$onPreProcess
callback hook for processing prior to saving the form's data object - individual renderers may overri...

◆ renderField()

◆ renderOnSubmitHandler()

FieldRenderer::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 in HTMLFieldRenderer, and CurrencyFieldRenderer.

Definition at line 252 of file field_renderers.inc.

253  {
254  // No output by default
255  }

◆ renderScript()

◆ renderSearchField()

FieldRenderer::renderSearchField (   $field,
  $mode 
)

◆ renderSearchScript()

FieldRenderer::renderSearchScript (   $field,
  $mode 
)

FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form.

Parameters
string$fieldthe field name
string$modethe search mode for the specific field ('equal', 'like', 'from', 'to', 'range')

Reimplemented in DateTimeFieldRenderer, DateOfBirthFieldRenderer, DateFieldRenderer, and CheckListFieldRenderer.

Definition at line 229 of file field_renderers.inc.

230  {
231  // No output by default
232  }

Member Data Documentation

◆ $annotateBefore

FieldRenderer::$annotateBefore = false

Definition at line 60 of file field_renderers.inc.

◆ $annotateNextLine

FieldRenderer::$annotateNextLine = true

Definition at line 61 of file field_renderers.inc.

◆ $colspan

FieldRenderer::$colspan = 1

Definition at line 59 of file field_renderers.inc.

◆ $hideLabel

FieldRenderer::$hideLabel = false

Definition at line 62 of file field_renderers.inc.

◆ $labelSuffix

FieldRenderer::$labelSuffix = ""

Definition at line 58 of file field_renderers.inc.

◆ $onPostProcess

FieldRenderer::$onPostProcess = null

callback hook for processing after saving the form's data object - individual renderers may override with custom processing

Definition at line 64 of file field_renderers.inc.

◆ $onPreProcess

FieldRenderer::$onPreProcess = null

callback hook for processing prior to saving the form's data object - individual renderers may override with custom processing

Definition at line 63 of file field_renderers.inc.

◆ $parent

FieldRenderer::$parent = null

Definition at line 57 of file field_renderers.inc.


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