38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
60 $this->options = array();
64 if ($form->data->hasField($field))
66 $form->override($field, $label, $this);
67 if ($this->options ==
null)
69 $opt = $form->data->distinctValues($field,
true);
72 $this->options = array_combine($opt, $opt);
76 $this->options = array();
82 $form->add($this, $field);
84 $form->overrides[$field][
'label'] = $label;
88 function add($title, $field, $items, $format)
90 $this->options[$field] = array(
"title" => $title,
94 $this->parent->hide($field);
106 $style =
"style='width: {$this->width}'";
107 echo
"<select $style name='$field' id='{$this->parent->id}_{$field}'";
109 if ($this->onChange !=
"")
110 echo
" onchange='$this->onChange(this)'";
111 elseif($this->addEntry)
112 echo
" onchange='onChange_{$this->parent->id}_{$field}(this)'";
116 if ($this->defaultBlank)
118 echo
"<option value=''></option>";
121 foreach($this->options as $subField => $group)
124 $groupName = $group[
"title"];
126 echo
"<optgroup label=\"$groupName\">\n";
128 foreach($group[
"items"] as $item)
130 $value =
"$subField:".$item->get($subField);
131 $name = $item->format($group[
"format"]);
133 $name = htmlSafe($name);
134 $trunced = $this->max_chars ?
ellipsis($name, $this->max_chars,
true) : $name;
136 if($current == $value)
138 $selected =
" selected";
143 $optionTitle = ($name != $trunced) ?
" title='$name'" :
"";
145 echo
"<option$optionTitle value='".htmlSafe($value).
"'$selected>$trunced</option>\n";
148 echo
"</optgroup>\n";
159 $obj = $this->parent->data;
161 foreach(array_keys($this->options) as $field)
163 $value = $obj->get($field);
166 return "$field:$value";
175 $obj = $this->parent->data;
177 $value = ($this->parent->method ==
"POST") ? $_POST[$field] : $_GET[$field];
179 list($targetField, $value) = explode(
":", $value);
181 foreach(array_keys($this->options) as $f)
183 if ($targetField == $f)
185 $obj->set($f, $value);
189 $obj->set($f, $this->emptyValue);
CompoundSelectFieldRenderer allows you to provide a consolidated grouped dropdown selector that proce...
renderField($field)
FieldRenderers must override this method to provide the HTML implementation of the control used to ed...
CompoundSelectFieldRenderer(&$form, $field, $label, $onChange)
$defaultBlank
whether the drop down includes a blank as the default
add($title, $field, $items, $format)
$onChange
optional selection change handler
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
$emptyValue
The value to which the non-selected fields should be set.
FieldRenderer is the abstract base class for all FieldRenderers.
_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.
FieldRenderer($parent)
Constructor.
ellipsis($txt, $max, $wholeWord=false)
Truncate the supplied text at the given maximum length.