Framework  3.9
OptionCheckListFieldRenderer Class Reference

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

+ Inheritance diagram for OptionCheckListFieldRenderer:
+ Collaboration diagram for OptionCheckListFieldRenderer:

Public Member Functions

 OptionCheckListFieldRenderer (&$form, $field, $label, $options)
 
 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()
 
 $cssClass = "options_list"
 
 $separator = ", "
 
- 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 number of items.

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.

Author
Andy

Definition at line 48 of file option_checklist_field_renderer.inc.

Member Function Documentation

◆ OptionCheckListFieldRenderer()

OptionCheckListFieldRenderer::OptionCheckListFieldRenderer ( $form,
  $field,
  $label,
  $options 
)

Definition at line 54 of file option_checklist_field_renderer.inc.

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

◆ renderField()

OptionCheckListFieldRenderer::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 111 of file option_checklist_field_renderer.inc.

112  {
113  $this->_startField($field);
114 
115  $value = $this->parent->data->get($field);
116 
117  $values = explode(",", $value);
118  $values = array_combine($values, $values);
119 
120  $id = "{$this->parent->id}_{$field}";
121 
122  echo "<input type='hidden' id='{$id}' name='{$field}' value='{$value}'/>";
123  echo "<ul id='{$id}_list' class='{$this->cssClass}'>";
124  foreach($this->options as $option => $description)
125  {
126  $selected = ($values[$option] == $option) ? " class='selected'" : "";
127  echo "<li{$selected} data-value='{$option}' onclick='{$id}_update(this); return false;'>{$description}</li>\n";
128  }
129  echo "</ul>";
130  $this->_endField($field);
131  }
_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()

OptionCheckListFieldRenderer::renderReadOnly (   $field)

Definition at line 133 of file option_checklist_field_renderer.inc.

134  {
135  $this->_startField($field);
136 
137  $text = array();
138  $value = $this->parent->data->get($field);
139  $values = explode(",", $value);
140 
141  foreach($values as $v)
142  {
143  $text[] = $this->options[$v];
144  }
145 
146  echo implode($this->separator, $text);
147 
148  $this->_endField($field);
149  }

◆ renderScript()

OptionCheckListFieldRenderer::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 70 of file option_checklist_field_renderer.inc.

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

Member Data Documentation

◆ $cssClass

OptionCheckListFieldRenderer::$cssClass = "options_list"

Definition at line 51 of file option_checklist_field_renderer.inc.

◆ $options

OptionCheckListFieldRenderer::$options = array()

Definition at line 50 of file option_checklist_field_renderer.inc.

◆ $separator

OptionCheckListFieldRenderer::$separator = ", "

Definition at line 52 of file option_checklist_field_renderer.inc.


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