Framework  3.9
CompoundSelectFieldRenderer Class Reference

CompoundSelectFieldRenderer allows you to provide a consolidated grouped dropdown selector that processes selection for multiple fields. More...

+ Inheritance diagram for CompoundSelectFieldRenderer:
+ Collaboration diagram for CompoundSelectFieldRenderer:

Public Member Functions

 CompoundSelectFieldRenderer (&$form, $field, $label, $onChange)
 
 add ($title, $field, $items, $format)
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 getValue ()
 
 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...
 
- 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...
 
 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...
 
 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...
 
 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
 
 $onChange
 optional selection change handler More...
 
 $width
 
 $max_chars
 
 $defaultBlank = true
 whether the drop down includes a blank as the default More...
 
 $defaultText = "Choose One"
 
 $emptyValue = 0
 The value to which the non-selected fields should be set. 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

CompoundSelectFieldRenderer allows you to provide a consolidated grouped dropdown selector that processes selection for multiple fields.

Author
andy

Definition at line 47 of file compound_select_field_renderer.inc.

Member Function Documentation

◆ add()

CompoundSelectFieldRenderer::add (   $title,
  $field,
  $items,
  $format 
)

Definition at line 88 of file compound_select_field_renderer.inc.

89  {
90  $this->options[$field] = array("title" => $title,
91  "items" => $items,
92  "format" => $format);
93 
94  $this->parent->hide($field);
95 
96  return $this;
97  }

◆ CompoundSelectFieldRenderer()

CompoundSelectFieldRenderer::CompoundSelectFieldRenderer ( $form,
  $field,
  $label,
  $onChange 
)

Definition at line 58 of file compound_select_field_renderer.inc.

59  {
60  $this->options = array();
61  $this->onChange = $onChange;
62 
63  $this->FieldRenderer($form);
64  if ($form->data->hasField($field))
65  {
66  $form->override($field, $label, $this);
67  if ($this->options == null)
68  {
69  $opt = $form->data->distinctValues($field, true);
70  if (count($opt) > 0)
71  {
72  $this->options = array_combine($opt, $opt);
73  }
74  else
75  {
76  $this->options = array();
77  }
78  }
79  }
80  else
81  {
82  $form->add($this, $field);
83  // JDG 7/22/2011 - allow "additional" fields to override label
84  $form->overrides[$field]['label'] = $label;
85  }
86  }
$onChange
optional selection change handler
FieldRenderer($parent)
Constructor.

◆ getValue()

CompoundSelectFieldRenderer::getValue ( )

Definition at line 157 of file compound_select_field_renderer.inc.

158  {
159  $obj = $this->parent->data;
160 
161  foreach(array_keys($this->options) as $field)
162  {
163  $value = $obj->get($field);
164  if ($value)
165  {
166  return "$field:$value";
167  }
168  }
169 
170  return "";
171  }

◆ preProcess()

CompoundSelectFieldRenderer::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.

For example, the FileUploadFieldRenderer overrides this method to process the uploading of the file and then store the location in the associated field in the target object.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 173 of file compound_select_field_renderer.inc.

174  {
175  $obj = $this->parent->data;
176 
177  $value = ($this->parent->method == "POST") ? $_POST[$field] : $_GET[$field];
178 
179  list($targetField, $value) = explode(":", $value);
180 
181  foreach(array_keys($this->options) as $f)
182  {
183  if ($targetField == $f)
184  {
185  $obj->set($f, $value);
186  }
187  else
188  {
189  $obj->set($f, $this->emptyValue);
190  }
191  }
192  }

◆ renderField()

CompoundSelectFieldRenderer::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 99 of file compound_select_field_renderer.inc.

100  {
101  $this->_startField($field);
102 
103  $current = $this->getValue();
104 
105  if($this->width)
106  $style = "style='width: {$this->width}'";
107  echo "<select $style name='$field' id='{$this->parent->id}_{$field}'";
108 
109  if ($this->onChange != "")
110  echo " onchange='$this->onChange(this)'";
111  elseif($this->addEntry)
112  echo " onchange='onChange_{$this->parent->id}_{$field}(this)'";
113 
114  echo ">\n";
115 
116  if ($this->defaultBlank)
117  {
118  echo "<option value=''></option>";
119  }
120 
121  foreach($this->options as $subField => $group)
122  {
123 
124  $groupName = $group["title"];
125 
126  echo "<optgroup label=\"$groupName\">\n";
127 
128  foreach($group["items"] as $item)
129  {
130  $value = "$subField:".$item->get($subField);
131  $name = $item->format($group["format"]);
132 
133  $name = htmlSafe($name);
134  $trunced = $this->max_chars ? ellipsis($name, $this->max_chars, true) : $name;
135 
136  if($current == $value)
137  {
138  $selected = " selected";
139  }
140  else
141  $selected = "";
142 
143  $optionTitle = ($name != $trunced) ? " title='$name'" : "";
144 
145  echo "<option$optionTitle value='".htmlSafe($value)."'$selected>$trunced</option>\n";
146  }
147 
148  echo "</optgroup>\n";
149  }
150 
151  echo "</select>\n";
152 
153  $this->_endField($field);
154  }
_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.
ellipsis($txt, $max, $wholeWord=false)
Truncate the supplied text at the given maximum length.
Definition: functions.inc:779

Member Data Documentation

◆ $defaultBlank

CompoundSelectFieldRenderer::$defaultBlank = true

whether the drop down includes a blank as the default

Definition at line 54 of file compound_select_field_renderer.inc.

◆ $defaultText

CompoundSelectFieldRenderer::$defaultText = "Choose One"

Definition at line 55 of file compound_select_field_renderer.inc.

◆ $emptyValue

CompoundSelectFieldRenderer::$emptyValue = 0

The value to which the non-selected fields should be set.

Definition at line 56 of file compound_select_field_renderer.inc.

◆ $max_chars

CompoundSelectFieldRenderer::$max_chars

Definition at line 52 of file compound_select_field_renderer.inc.

◆ $onChange

CompoundSelectFieldRenderer::$onChange

optional selection change handler

Definition at line 50 of file compound_select_field_renderer.inc.

◆ $options

CompoundSelectFieldRenderer::$options

Definition at line 49 of file compound_select_field_renderer.inc.

◆ $width

CompoundSelectFieldRenderer::$width

Definition at line 51 of file compound_select_field_renderer.inc.


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