10 defined(
'JPATH_PLATFORM') or die;
28 protected $type =
'GroupedList';
38 protected function getGroups()
43 foreach ($this->element->children() as $element)
45 switch ($element->getName())
50 if (!isset($groups[$label]))
52 $groups[$label] = array();
55 $disabled = (string) $element[
'disabled'];
56 $disabled = ($disabled ==
'true' || $disabled ==
'disabled' || $disabled ==
'1');
60 'select.option', ($element[
'value']) ? (
string) $element[
'value'] : trim((
string) $element),
61 JText::alt(trim((
string) $element), preg_replace(
'/[^a-zA-Z0-9_\-]/',
'_', $this->fieldname)),
'value',
'text',
66 $tmp->class = (string) $element[
'class'];
69 $tmp->onclick = (string) $element[
'onclick'];
72 $groups[$label][] = $tmp;
78 if ($groupLabel = (
string) $element[
'label'])
84 if (!isset($groups[$label]))
86 $groups[$label] = array();
90 foreach ($element->children() as $option)
93 if ($option->getName() !=
'option')
98 $disabled = (string) $option[
'disabled'];
99 $disabled = ($disabled ==
'true' || $disabled ==
'disabled' || $disabled ==
'1');
103 'select.option', ($option[
'value']) ? (
string) $option[
'value'] :
JText::_(trim((
string) $option)),
104 JText::_(trim((
string) $option)),
'value',
'text', $disabled
108 $tmp->class = (string) $option[
'class'];
111 $tmp->onclick = (string) $option[
'onclick'];
114 $groups[$label][] = $tmp;
119 $label = count($groups);
125 throw new UnexpectedValueException(sprintf(
'Unsupported element %s in JFormFieldGroupedList', $element->getName()), 500);
142 protected function getInput()
148 $attr .= !empty($this->
class) ?
' class="' . $this->
class . '"' : '';
149 $attr .= $this->disabled ? ' disabled' : '';
150 $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
151 $attr .= $this->multiple ? ' multiple' : '';
152 $attr .= $this->required ? ' required aria-required="true"' : '';
153 $attr .= $this->autofocus ? ' autofocus' : '';
156 $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
159 $groups = (array) $this->getGroups();
165 'select.groupedlist', $groups, null,
167 'list.attr' => $attr,
'id' => $this->
id,
'list.select' => $this->value,
'group.items' => null,
'option.key.toHtml' =>
false,
168 'option.text.toHtml' =>
false
171 $html[] =
'<input type="hidden" name="' . $this->name .
'" value="' . $this->value .
'"/>';
178 'select.groupedlist', $groups, $this->name,
180 'list.attr' => $attr,
'id' => $this->
id,
'list.select' => $this->value,
'group.items' => null,
'option.key.toHtml' =>
false,
181 'option.text.toHtml' =>
false
186 return implode($html);