Framework  3.9
BooleanFieldRenderer Class Reference

Field renderer for boolean data fields. More...

+ Inheritance diagram for BooleanFieldRenderer:
+ Collaboration diagram for BooleanFieldRenderer:

Public Member Functions

 BooleanFieldRenderer (&$parent, $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...
 
- 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 checkbox.

Definition at line 42 of file boolean_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

BooleanFieldRenderer::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 63 of file boolean_field_renderer.inc.

64  {
65  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
66 
67  if($required)
68  {
69  $this->parent->validator->add(new RequiredBooleanValidator($field, $label));
70  }
71 
72  }
RequiredBoolean Validator.

◆ BooleanFieldRenderer()

BooleanFieldRenderer::BooleanFieldRenderer ( $parent,
  $field = null,
  $label = null 
)

Create a new BooleanFieldRenderer.

Parameters
AutoForm$parentthe parent form

Definition at line 52 of file boolean_field_renderer.inc.

53  {
54  $this->FieldRenderer($parent);
55  $this->colspan = 2;
56  $this->hideLabel = true;
57  if ($field && !$parent->data->hasField($field))
58  {
59  $parent->add($this, $field, $label);
60  }
61  }
FieldRenderer($parent)
Constructor.

◆ format()

BooleanFieldRenderer::format (   $field)

Definition at line 117 of file boolean_field_renderer.inc.

118  {
119  return BooleanTypeRenderer::format($this->parent->data->get($field), $this->template);
120  }
static format($value, $template="")

◆ renderField()

BooleanFieldRenderer::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 75 of file boolean_field_renderer.inc.

76  {
77  $this->_startField($field);
78  $disable = ($this->disable) ? "disabled='disabled'" : "";
79  $onClick = ($this->onClick) ? " onclick='return {$this->onClick}(this.checked);'" : "";
80  echo "<input id='{$this->parent->id}_{$field}' type='checkbox' class='checkbox' value='1' name='$field'";
81  if ($this->parent->data->get($field))
82  {
83  echo " checked";
84  }
85  echo " {$disable}{$onClick}>&nbsp;<label for='{$this->parent->id}_{$field}' class='label'>";
86  echo $this->_getLabel($field, false);
87  echo "</label>";
88 
89  $this->_endField($field);
90  }
$onClick
Name of Javascript function to be called when checkbox is toggled.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_getLabel($field, $addSuffix=true)
_endField($field)
Internal method to generate the closing HTML for the field.

◆ renderReadOnly()

BooleanFieldRenderer::renderReadOnly (   $field)

Definition at line 107 of file boolean_field_renderer.inc.

108  {
109  $this->colspan = 1;
110  $this->hideLabel = false;
111 
112  $this->_startField($field);
113  echo $this->format($field);
114  $this->_endField($field);
115  }

◆ renderSearchField()

BooleanFieldRenderer::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 92 of file boolean_field_renderer.inc.

93  {
94  echo "<tr>\n";
95  echo "<td colspan='2'";
96  if ($this->parent->labelCSS) echo " class='{$this->parent->labelCSS}'";
97  echo "><input type='checkbox' value='1' name='$field:$mode'";
98  if ($this->parent->params->get($field, $mode))
99  {
100  echo " checked";
101  }
102  echo ">&nbsp;";
103  echo $this->parent->prettifyFieldName($field);
104  echo "</td>\n</tr>\n";
105  }

Member Data Documentation

◆ $disable

BooleanFieldRenderer::$disable = false

Definition at line 44 of file boolean_field_renderer.inc.

◆ $onClick

BooleanFieldRenderer::$onClick = null

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

Definition at line 46 of file boolean_field_renderer.inc.

◆ $template

BooleanFieldRenderer::$template = "Yes/No"

, alternative to readonly; field can be reenabled thru javascript

How to format read only

Definition at line 45 of file boolean_field_renderer.inc.


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