Framework  3.9
OptionListFieldRenderer Class Reference

Displays a control that provides a highly styleable set of options from which the user can select a single item. More...

+ Inheritance diagram for OptionListFieldRenderer:
+ Collaboration diagram for OptionListFieldRenderer:

Public Member Functions

 OptionListFieldRenderer (&$form, $field, $label, $options, $grouped=false)
 
 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...
 
 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...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. 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...
 
 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...
 
 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 = array()
 The array of options for the control to display, as value=>description pairs. More...
 
 $cssClass = "options_list"
 CSS class for the generated list of options. Use this to override the look and feel. More...
 
 $grouped = false
 True if the $options array is grouped by headings, false if not. More...
 
 $groupTag = "h6"
 The tag to use when displaying the groups. 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

Displays a control that provides a highly styleable set of options from which the user can select a single item.

The optons are provided as an array of value-description pairs, and are rendered as an unordered list in HTML, with javascript to provide the selection interaction. Clicking on one of the items will select the associated value. The currently selected list item is given the "selected" CSS class. Options can also be provided grouped as an associative array with the group headings as the keys.

Author
Andy

Definition at line 49 of file option_list_field_renderer.inc.

Member Function Documentation

◆ OptionListFieldRenderer()

OptionListFieldRenderer::OptionListFieldRenderer ( $form,
  $field,
  $label,
  $options,
  $grouped = false 
)

Definition at line 56 of file option_list_field_renderer.inc.

57  {
58  $this->options = $options;
59  $this->grouped = $grouped;
60 
61  $this->FieldRenderer($form);
62  if ($form->data->hasField($field))
63  {
64  $form->override($field, $label, $this);
65  }
66  else
67  {
68  $form->add($this, $field);
69  if ($label) $form->alias($field, $label);
70  }
71  }
FieldRenderer($parent)
Constructor.
$options
The array of options for the control to display, as value=>description pairs.
$grouped
True if the $options array is grouped by headings, false if not.

◆ renderField()

OptionListFieldRenderer::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 110 of file option_list_field_renderer.inc.

111  {
112  $this->_startField($field);
113 
114  $value = $this->parent->data->get($field);
115 
116  $id = "{$this->parent->id}_{$field}";
117 
118  echo "<input type='hidden' id='{$id}' name='{$field}' value='{$value}'/>";
119  if (!$this->grouped)
120  {
121  echo "<ul id='{$id}_list' class='{$this->cssClass}'>";
122  foreach($this->options as $option => $description)
123  {
124  $selected = ($value == $option) ? " class='selected'" : "";
125  echo "<li{$selected} data-value='{$option}' onclick='{$id}_update(this); return false;'>{$description}</li>\n";
126  }
127  echo "</ul>";
128  }
129  else
130  {
131  echo "<div id='{$id}_list' class='{$this->cssClass}'>";
132 
133  foreach($this->options as $group => $options)
134  {
135  echo "<{$this->groupTag}>{$group}</{$this->groupTag}>\n";
136  echo "<ul class='{$this->cssClass}'>";
137  foreach($options as $option => $description)
138  {
139  $selected = ($value == $option) ? " class='selected'" : "";
140  echo "<li{$selected} data-value='{$option}' onclick='{$id}_update(this); return false;'>{$description}</li>\n";
141  }
142  echo "</ul>";
143  }
144 
145  echo "</div>";
146  }
147 
148  $this->_endField($field);
149  }
_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()

OptionListFieldRenderer::renderReadOnly (   $field)

Definition at line 151 of file option_list_field_renderer.inc.

152  {
153  $this->_startField($field);
154 
155  $value = $this->parent->data->get($field);
156  if ($value)
157  {
158  echo $this->options[$value];
159  }
160  $this->_endField($field);
161  }

◆ renderScript()

OptionListFieldRenderer::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 74 of file option_list_field_renderer.inc.

75  {
76  if ($this->parent->readOnlyForm || $this->parent->isReadOnly($field)) return;
77  $id = "{$this->parent->id}_{$field}";
78  ?>
79  <script type='text/javascript'>
80  function <?echo $id?>_update(sel)
81  {
82  value = sel.get('data-value');
83 
84  $$('#<?echo $id?>_list li[data-value]').each(function(elt)
85  {
86  var v = elt.get('data-value');
87  if (v == value)
88  {
89  elt.addClass('selected');
90  }
91  else
92  {
93  elt.removeClass('selected');
94  }
95  });
96 
97  var hidden = document.id('<?echo $id?>');
98  var v = hidden.value;
99  hidden.value = value;
100  var f = document.id('<?echo $this->parent->id?>');
101  if (v != hidden.value && f && f.manager)
102  {
103  f.manager.dirty();
104  }
105  }
106  </script>
107 <?
108  }

Member Data Documentation

◆ $cssClass

OptionListFieldRenderer::$cssClass = "options_list"

CSS class for the generated list of options. Use this to override the look and feel.

Definition at line 52 of file option_list_field_renderer.inc.

◆ $grouped

OptionListFieldRenderer::$grouped = false

True if the $options array is grouped by headings, false if not.

Definition at line 53 of file option_list_field_renderer.inc.

◆ $groupTag

OptionListFieldRenderer::$groupTag = "h6"

The tag to use when displaying the groups.

Definition at line 54 of file option_list_field_renderer.inc.

◆ $options

OptionListFieldRenderer::$options = array()

The array of options for the control to display, as value=>description pairs.

Definition at line 51 of file option_list_field_renderer.inc.


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