Framework  3.9
PushButtonFieldRenderer Class Reference

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

+ Inheritance diagram for PushButtonFieldRenderer:
+ Collaboration diagram for PushButtonFieldRenderer:

Public Member Functions

 PushButtonFieldRenderer (&$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...
 
 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...
 
 renderButtons ($field, $mode=null)
 
 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...
 
 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 = true
 
 $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 push_button_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

PushButtonFieldRenderer::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 push_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 RequiredValidator($field, $label));
79  }
80 
81  }
RequiredField Validator.
Definition: validation.inc:76

◆ PushButtonFieldRenderer()

PushButtonFieldRenderer::PushButtonFieldRenderer ( $form,
  $field,
  $label,
  $options,
  $onChange = "" 
)

Definition at line 54 of file push_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.

◆ renderButtons()

PushButtonFieldRenderer::renderButtons (   $field,
  $mode = null 
)

Definition at line 121 of file push_button_field_renderer.inc.

122  {
123  $current = $this->parent->data->get($field);
124 
125  $separator = "";
126 
127  if ($this->regular && !$this->tabular)
128  {
129  $width = 100 / count($this->options);
130  $widthStyle = " style='width: {$width}%'";
131  }
132 
133  $containerId = "{$this->parent->id}_{$field}_container";
134 
135  if ($this->tabular)
136  {
137  if ($this->regular)
138  {
139  $width = 100 / count($this->options);
140  $tdStyle = " style='width: {$width}%'";
141  }
142  else
143  {
144  $tdStyle = "";
145  }
146 
147  echo "<table id='{$containerId}' class='push_button_options'><tr><td{$tdStyle}>";
148  $separator = "</td><td{$tdStyle}>";
149  $close = "</td></tr></table>";
150  }
151  else if ($this->horizontal)
152  {
153  echo "<div id='{$containerId}' class='push_button_options horizontal'>";
154  $close = "</div>";
155  }
156  else
157  {
158  echo "<div id='{$containerId}' class='push_button_options vertical'>";
159  $close = "</div>";
160  }
161 
162  $name = $mode ? "$field:$mode" : $field;
163 
164  echo "<input type='hidden' id='{$this->parent->id}_{$field}' name='{$name}' value='$current'/>";
165 
166  $out = array();
167 
168  $max = count($this->options) - 1;
169  $disable = ($this->disable) ? "disabled='disabled'" : "";
170 
171  $count = 0;
172  foreach($this->options as $value => $name)
173  {
174  $selected = ($current == $value) ? " selected" : "";
175  $onChange = ($this->onChange) ? "{$this->onChange}(this);" : "";
176 
177  $position = "";
178  if ($count == 0) $position .= " first";
179  if ($count == $max) $position .= " last";
180 
181  // JDG 3/34/10, add border: none to correct IE8 display issue
182  $out[] = "<a class='pushbutton{$position}{$selected}'{$widthStyle} href='#' onclick='{$this->parent->id}_{$field}_update(this, \"{$value}\");{$onChange}return false' {$disable}/>{$name}</a>";
183 
184  $count++;
185  }
186 
187  $buttons = implode($separator, $out);
188  $buttons .= $close;
189 
190  echo $buttons;
191  }

◆ renderField()

PushButtonFieldRenderer::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 108 of file push_button_field_renderer.inc.

109  {
110  if (!count($this->options)) return;
111 
112  $this->_startField($field);
113 
114 
115  $this->renderButtons($field);
116 
117 
118  $this->_endField($field);
119  }
_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()

PushButtonFieldRenderer::renderReadOnly (   $field)

Definition at line 207 of file push_button_field_renderer.inc.

208  {
209  $this->_startField($field);
210 
211  if (array_key_exists($this->parent->data->get($field), $this->options))
212  {
213  echo $this->options[$this->parent->data->get($field)];
214  }
215  else
216  {
217  echo "Not specified";
218  }
219  $this->_endField($field);
220  }

◆ renderScript()

PushButtonFieldRenderer::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 84 of file push_button_field_renderer.inc.

85  {
86  $fn = "{$this->parent->id}_{$field}_update";
87  $containerId = "{$this->parent->id}_{$field}_container";
88  $id = "{$this->parent->id}_{$field}";
89 ?>
90 <script type='text/javascript'>
91 function <?echo $fn?>(element, value)
92 {
93  var container = document.id('<?echo $containerId?>');
94  container.getElements("a.selected").each(function(elt)
95  {
96  elt.removeClass('selected');
97  });
98  document.id(element).addClass('selected');
99  var ctrl = document.id('<?echo $id?>');
100  ctrl.value = value;
101  ctrl.fireEvent('change');
102  return false;
103 }
104 </script>
105 <?
106  }

◆ renderSearchField()

PushButtonFieldRenderer::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 193 of file push_button_field_renderer.inc.

194  {
195  if ($mode != "equal") return;
196 
197  $searchValue = $this->parent->params->get($field, $mode);
198 
199  $this->_startField($field);
200 
201  $this->renderButtons($field, $mode);
202 
203  $this->_endField($field);
204  }

Member Data Documentation

◆ $disable

PushButtonFieldRenderer::$disable = false

Definition at line 50 of file push_button_field_renderer.inc.

◆ $horizontal

PushButtonFieldRenderer::$horizontal = true

Definition at line 48 of file push_button_field_renderer.inc.

◆ $onChange

PushButtonFieldRenderer::$onChange = ""

Definition at line 49 of file push_button_field_renderer.inc.

◆ $options

PushButtonFieldRenderer::$options

Definition at line 47 of file push_button_field_renderer.inc.

◆ $regular

PushButtonFieldRenderer::$regular = false

Definition at line 52 of file push_button_field_renderer.inc.

◆ $tabular

PushButtonFieldRenderer::$tabular = false

Definition at line 51 of file push_button_field_renderer.inc.


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