Framework  3.9
PushButtonCheckListFieldRenderer Class Reference

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

+ Inheritance diagram for PushButtonCheckListFieldRenderer:
+ Collaboration diagram for PushButtonCheckListFieldRenderer:

Public Member Functions

 PushButtonCheckListFieldRenderer (&$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, $readonly=false)
 
 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 buttons from which the user can choose one or more responses.

Definition at line 45 of file push_button_checklist_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

PushButtonCheckListFieldRenderer::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_checklist_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

◆ PushButtonCheckListFieldRenderer()

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

Definition at line 54 of file push_button_checklist_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()

PushButtonCheckListFieldRenderer::renderButtons (   $field,
  $mode = null,
  $readonly = false 
)

Definition at line 131 of file push_button_checklist_field_renderer.inc.

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

◆ renderField()

PushButtonCheckListFieldRenderer::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 119 of file push_button_checklist_field_renderer.inc.

120  {
121  if (!count($this->options)) return;
122 
123  $this->_startField($field);
124 
125  $this->renderButtons($field);
126 
127 
128  $this->_endField($field);
129  }
_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.
renderButtons($field, $mode=null, $readonly=false)

◆ renderReadOnly()

PushButtonCheckListFieldRenderer::renderReadOnly (   $field)

Definition at line 221 of file push_button_checklist_field_renderer.inc.

222  {
223  $this->_startField($field);
224 
225  $this->renderButtons($field, null, true);
226 
227  $this->_endField($field);
228  }

◆ renderScript()

PushButtonCheckListFieldRenderer::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_checklist_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)
92 {
93  var container = document.id('<?echo $containerId?>');
94 
95  element = document.id(element);
96  if (element.hasClass('selected'))
97  {
98  element.removeClass('selected');
99  }
100  else
101  {
102  element.addClass('selected');
103  }
104 
105  var values = [];
106 
107  container.getElements("a.selected").each(function(elt)
108  {
109  values.push(elt.get('data-value'));
110  });
111 
112  document.id('<?echo $id?>').value = values.join(",");
113  return false;
114 }
115 </script>
116 <?
117  }

◆ renderSearchField()

PushButtonCheckListFieldRenderer::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 207 of file push_button_checklist_field_renderer.inc.

208  {
209  if ($mode != "equal") return;
210 
211  $searchValue = $this->parent->params->get($field, $mode);
212 
213  $this->_startField($field);
214 
215  $this->renderButtons($field, $mode);
216 
217  $this->_endField($field);
218  }

Member Data Documentation

◆ $disable

PushButtonCheckListFieldRenderer::$disable = false

Definition at line 50 of file push_button_checklist_field_renderer.inc.

◆ $horizontal

PushButtonCheckListFieldRenderer::$horizontal = true

Definition at line 48 of file push_button_checklist_field_renderer.inc.

◆ $onChange

PushButtonCheckListFieldRenderer::$onChange = ""

Definition at line 49 of file push_button_checklist_field_renderer.inc.

◆ $options

PushButtonCheckListFieldRenderer::$options

Definition at line 47 of file push_button_checklist_field_renderer.inc.

◆ $regular

PushButtonCheckListFieldRenderer::$regular = false

Definition at line 52 of file push_button_checklist_field_renderer.inc.

◆ $tabular

PushButtonCheckListFieldRenderer::$tabular = false

Definition at line 51 of file push_button_checklist_field_renderer.inc.


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