Framework  3.9
ToggleFieldRenderer Class Reference

Field renderer for boolean data fields. More...

+ Inheritance diagram for ToggleFieldRenderer:
+ Collaboration diagram for ToggleFieldRenderer:

Public Member Functions

 ToggleFieldRenderer (&$parent, $ragged, $field=null, $label=null)
 Create a new BooleanFieldRenderer. 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...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderSearchField ($field, $mode="match")
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
 renderReadOnly ($field)
 
 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...
 
 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...
 
 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

 $disable = false
 
 $template = "Yes/No"
 , alternative to readonly; field can be reenabled thru javascript More...
 
 $onClick = null
 Name of Javascript function to be called when checkbox is toggled. More...
 
 $style = "round"
 
 $ragged = false
 
- 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 boolean data fields.

Renders as a toggle.

Definition at line 43 of file toggle_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

ToggleFieldRenderer::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 79 of file toggle_field_renderer.inc.

80  {
81  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
82 
83  if($required)
84  {
85  $this->parent->validator->add(new RequiredBooleanValidator($field, $label));
86  }
87 
88  }
RequiredBoolean Validator.

◆ format()

ToggleFieldRenderer::format (   $field)

Definition at line 141 of file toggle_field_renderer.inc.

142  {
143  return BooleanTypeRenderer::format($this->parent->data->get($field), $this->template);
144  }
static format($value, $template="")

◆ renderField()

ToggleFieldRenderer::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 91 of file toggle_field_renderer.inc.

92  {
93 
94 
95  $this->_startField($field);
96  $disable = ($this->disable) ? " disabled" : "";
97  $onClick = ($this->onClick) ? " onclick='return {$this->onClick}(this.checked);'" : "";
98 
99  if ($this->ragged)
100  {
101  echo "<label class='label' for='{$this->parent->id}_{$field}'>".$this->_getLabel($field, false)."</label>\n";
102  }
103 
104  echo "<label class='switch{$disable}'>";
105  echo "<input id='{$this->parent->id}_{$field}' type='checkbox' class='checkbox' value='1' name='$field'";
106  if ($this->parent->data->get($field))
107  {
108  echo " checked";
109  }
110  echo " {$disable}{$onClick}>&nbsp;<span class='slider {$this->style}'></span>";
111  echo "</label>";
112 
113  $this->_endField($field);
114  }
_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.
$onClick
Name of Javascript function to be called when checkbox is toggled.

◆ renderReadOnly()

ToggleFieldRenderer::renderReadOnly (   $field)

Definition at line 131 of file toggle_field_renderer.inc.

132  {
133  $this->colspan = 1;
134  $this->hideLabel = false;
135 
136  $this->_startField($field);
137  echo $this->format($field);
138  $this->_endField($field);
139  }

◆ renderSearchField()

ToggleFieldRenderer::renderSearchField (   $field,
  $mode = "match" 
)

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 116 of file toggle_field_renderer.inc.

117  {
118  echo "<tr>\n";
119  echo "<td colspan='2'";
120  if ($this->parent->labelCSS) echo " class='{$this->parent->labelCSS}'";
121  echo "><input type='checkbox' value='1' name='$field:$mode'";
122  if ($this->parent->params->get($field, $mode))
123  {
124  echo " checked";
125  }
126  echo ">&nbsp;";
127  echo $this->parent->prettifyFieldName($field);
128  echo "</td>\n</tr>\n";
129  }

◆ ToggleFieldRenderer()

ToggleFieldRenderer::ToggleFieldRenderer ( $parent,
  $ragged,
  $field = null,
  $label = null 
)

Create a new BooleanFieldRenderer.

Parameters
AutoForm$parentthe parent form

Definition at line 55 of file toggle_field_renderer.inc.

56  {
57  $this->FieldRenderer($parent);
58 
59  $this->ragged = $ragged;
60  if ($this->ragged)
61  {
62  $this->hideLabel = true;
63  $this->colspan = 2;
64  }
65 
66  if ($field)
67  {
68  if (!$parent->data->hasField($field))
69  {
70  $parent->add($this, $field, $label);
71  }
72  else
73  {
74  $parent->override($field, $label, $this);
75  }
76  }
77  }
FieldRenderer($parent)
Constructor.

Member Data Documentation

◆ $disable

ToggleFieldRenderer::$disable = false

Definition at line 45 of file toggle_field_renderer.inc.

◆ $onClick

ToggleFieldRenderer::$onClick = null

Name of Javascript function to be called when checkbox is toggled.

Definition at line 47 of file toggle_field_renderer.inc.

◆ $ragged

ToggleFieldRenderer::$ragged = false

Definition at line 49 of file toggle_field_renderer.inc.

◆ $style

ToggleFieldRenderer::$style = "round"

Definition at line 48 of file toggle_field_renderer.inc.

◆ $template

ToggleFieldRenderer::$template = "Yes/No"

, alternative to readonly; field can be reenabled thru javascript

How to format read only

Definition at line 46 of file toggle_field_renderer.inc.


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