10 defined(
'JPATH_PLATFORM') or die;
30 protected $type =
'Checkboxes';
38 protected $forceMultiple =
true;
57 public function __get($name)
62 case 'checkedOptions':
66 return parent::__get($name);
79 public function __set($name, $value)
83 case 'checkedOptions':
84 $this->checkedOptions = (string) $value;
88 parent::__set($name, $value);
106 public function setup(SimpleXMLElement $element, $value, $group = null)
108 $return = parent::setup($element, $value, $group);
112 $this->checkedOptions = (string) $this->element[
'checked'];
125 protected function getInput()
130 $class = !empty($this->
class) ?
' class=checkboxes "' . $this->
class . '"' : ' class="checkboxes"';
131 $checkedOptions = explode(',', (string) $this->checkedOptions);
132 $required = $this->required ? ' required aria-required="true"' : '';
133 $autofocus = $this->autofocus ? ' autofocus' : '';
136 JHtml::_('jquery.framework');
137 JHtml::_('script', 'system/html5fallback.js', false, true);
140 $html[] = '<fieldset id="' . $this->id . '"' . $class . $required . $autofocus . '>';
143 $options = $this->getOptions();
148 foreach ($options as $i => $option)
151 if (!isset($this->value) || empty($this->value))
153 $checked = (in_array((
string) $option->value, (array) $checkedOptions) ?
' checked' :
'');
157 $value = !is_array($this->value) ? explode(
',', $this->value) : $this->value;
158 $checked = (in_array((
string) $option->value, $value) ?
' checked' :
'');
161 $checked = empty($checked) && $option->checked ?
' checked' : $checked;
163 $class = !empty($option->class) ?
' class="' . $option->class .
'"' :
'';
164 $disabled = !empty($option->disable) || $this->disabled ?
' disabled' :
'';
167 $onclick = !empty($option->onclick) ?
' onclick="' . $option->onclick .
'"' :
'';
168 $onchange = !empty($option->onchange) ?
' onchange="' . $option->onchange .
'"' :
'';
171 $html[] =
'<input type="checkbox" id="' . $this->
id . $i .
'" name="' . $this->name .
'" value="'
172 . htmlspecialchars($option->value, ENT_COMPAT,
'UTF-8') .
'"' . $checked . $class . $onclick . $onchange . $disabled .
'/>';
174 $html[] =
'<label for="' . $this->
id . $i .
'"' . $class .
'>' .
JText::_($option->text) .
'</label>';
181 $html[] =
'</fieldset>';
183 return implode($html);
193 protected function getOptions()
197 foreach ($this->element->children() as $option)
200 if ($option->getName() !=
'option')
205 $disabled = (string) $option[
'disabled'];
206 $disabled = ($disabled ==
'true' || $disabled ==
'disabled' || $disabled ==
'1');
208 $checked = (string) $option[
'checked'];
209 $checked = ($checked ==
'true' || $checked ==
'checked' || $checked ==
'1');
212 $tmp = JHtml::_(
'select.option', (
string) $option[
'value'], trim((
string) $option),
'value',
'text', $disabled);
215 $tmp->class = (string) $option[
'class'];
216 $tmp->checked = $checked;
219 $tmp->onclick = (string) $option[
'onclick'];
220 $tmp->onchange = (string) $option[
'onchange'];