Framework  3.9
RadioButtonFieldRenderer Class Reference

Field renderer for data fields that must be displayed as a list of choices. More...

+ Inheritance diagram for RadioButtonFieldRenderer:
+ Collaboration diagram for RadioButtonFieldRenderer:

Public Member Functions

 RadioButtonFieldRenderer (&$form, $field, $label, $options, $onchange="")
 
 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)
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
 renderReadOnly ($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

 $options
 
 $horizontal = false
 
 $onChange = ""
 
 $disable = false
 
 $tabular = false
 
 $regular = 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 data fields that must be displayed as a list of choices.

Renders as a set of radio buttons from which the user can choose only one response.

Definition at line 45 of file radio_button_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

RadioButtonFieldRenderer::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 71 of file radio_button_field_renderer.inc.

72  {
73  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
74 
75  // JDG 2/2012 - changed from tree validator expects a div and does not match the rendering of this type
76  if($required)
77  {
78  $this->parent->validator->add(new RequiredRadioButtonValidator($field, $label));
79  }
80 
81  }

◆ RadioButtonFieldRenderer()

RadioButtonFieldRenderer::RadioButtonFieldRenderer ( $form,
  $field,
  $label,
  $options,
  $onchange = "" 
)

Definition at line 54 of file radio_button_field_renderer.inc.

55  {
56  $this->options = $options;
57  $this->onChange = $onchange;
58 
59  $this->FieldRenderer($form);
60  if ($form->data->hasField($field))
61  {
62  $form->override($field, $label, $this);
63  }
64  else
65  {
66  $form->add($this, $field);
67  $form->alias($field, $label);
68  }
69  }
FieldRenderer($parent)
Constructor.

◆ renderField()

RadioButtonFieldRenderer::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 84 of file radio_button_field_renderer.inc.

85  {
86  if (!count($this->options)) return;
87 
88  if(($this->horizontal || $this->tabular) && count($this->options) > 2)
89  $this->colspan = 2;
90  $this->_startField($field);
91 
92  $current = $this->parent->data->get($field);
93 
94  $separator = "<br/>";
95 
96  if ($this->tabular)
97  {
98  if ($this->regular)
99  {
100  if ($this->horizontal)
101  {
102  $width = 100 / count($this->options);
103  }
104  else
105  {
106  $width = 100;
107  }
108  $tdStyle = " style='width: {$width}%'";
109  }
110  else
111  {
112  $tdStyle = "";
113  }
114 
115  echo "<table class='radio_button_options'><tr><td{$tdStyle}>";
116  $separator = $this->horizontal ? "</td><td>" : "</td></tr><tr><td>";
117  }
118  else if ($this->horizontal)
119  {
120  $separator = "&nbsp;&nbsp;";
121  }
122 
123  $out = array();
124 
125  foreach($this->options as $value => $name)
126  {
127  $selected = ($current == $value) ? " checked" : "";
128  $onchange = ($this->onChange) ? "onclick='$this->onChange(this)'" : "";
129  $disable = ($this->disable) ? "disabled='disabled'" : "";
130 
131  // JDG 3/34/10, add border: none to correct IE8 display issue
132  $out[] = "<label class='radio' for='{$this->parent->id}_{$field}_{$value}'><input id='{$this->parent->id}_{$field}_{$value}' style='border: none' type='radio' name='$field' value='$value'$selected $onchange $disable/>&nbsp;$name</label>";
133  }
134 
135  $radios = implode($separator, $out);
136  if ($this->tabular)
137  {
138  $radios .= "</td></tr></table>";
139  }
140 
141  echo $radios;
142 
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()

RadioButtonFieldRenderer::renderReadOnly (   $field)

Definition at line 168 of file radio_button_field_renderer.inc.

169  {
170  $this->_startField($field);
171 
172  if (array_key_exists($this->parent->data->get($field), $this->options))
173  {
174  echo $this->options[$this->parent->data->get($field)];
175  }
176  else
177  {
178  echo "Not specified";
179  }
180  $this->_endField($field);
181  }

◆ renderSearchField()

RadioButtonFieldRenderer::renderSearchField (   $field,
  $mode 
)

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 150 of file radio_button_field_renderer.inc.

151  {
152  if ($mode != "equal") return;
153 
154  $searchValue = $this->parent->params->get($field, $mode);
155  echo "<tr>\n";
156  $this->_printLabel($field);
157  echo "<td>\n";
158  foreach($this->options as $value => $name)
159  {
160  $selected = ($searchValue == $value) ? " checked" : "";
161  echo "<input style='border: none' type='radio' name='$field:$mode' value='$value'$selected>$name</option>";
162  echo ($this->horizontal) ? "&nbsp;&nbsp;" : "<br/>";
163  }
164  echo "</td></tr>\n";
165  }
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.

Member Data Documentation

◆ $disable

RadioButtonFieldRenderer::$disable = false

Definition at line 50 of file radio_button_field_renderer.inc.

◆ $horizontal

RadioButtonFieldRenderer::$horizontal = false

Definition at line 48 of file radio_button_field_renderer.inc.

◆ $onChange

RadioButtonFieldRenderer::$onChange = ""

Definition at line 49 of file radio_button_field_renderer.inc.

◆ $options

RadioButtonFieldRenderer::$options

Definition at line 47 of file radio_button_field_renderer.inc.

◆ $regular

RadioButtonFieldRenderer::$regular = false

Definition at line 52 of file radio_button_field_renderer.inc.

◆ $tabular

RadioButtonFieldRenderer::$tabular = false

Definition at line 51 of file radio_button_field_renderer.inc.


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