Source for file checkboxes.php
Documentation is available at checkboxes.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Form Field class for the Joomla Platform.
* Displays options as a list of check boxes.
* Multiselect may be forced to be true.
* @package Joomla.Platform
* @see JFormFieldCheckbox
protected $type =
'Checkboxes';
* Flag to tell the field to always be in multiple values mode.
* The comma seprated list of checked checkboxes value.
* Method to get certain otherwise inaccessible properties from the form field object.
* @param string $name The property name for which to the the value.
* @return mixed The property value or null.
public function __get($name)
return parent::__get($name);
* Method to set certain otherwise inaccessible properties of the form field object.
* @param string $name The property name for which to the the value.
* @param mixed $value The value of the property.
public function __set($name, $value)
parent::__set($name, $value);
* Method to attach a JForm object to the field.
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @return boolean True on success.
* @see JFormField::setup()
public function setup(SimpleXMLElement $element, $value, $group =
null)
$return =
parent::setup($element, $value, $group);
* Method to get the field input markup for check boxes.
* @return string The field input markup.
// Initialize some field attributes.
$class =
!empty($this->class) ?
' class=checkboxes "' .
$this->class .
'"' :
' class="checkboxes"';
$required =
$this->required ?
' required aria-required="true"' :
'';
$autofocus =
$this->autofocus ?
' autofocus' :
'';
// Including fallback code for HTML5 non supported browsers.
JHtml::_('script', 'system/html5fallback.js', false, true);
// Start the checkbox field output.
$html[] =
'<fieldset id="' .
$this->id .
'"' .
$class .
$required .
$autofocus .
'>';
// Get the field options.
// Build the checkbox field output.
foreach ($options as $i =>
$option)
// Initialize some option attributes.
$checked =
(in_array((string)
$option->value, (array)
$checkedOptions) ?
' checked' :
'');
$checked =
(in_array((string)
$option->value, $value) ?
' checked' :
'');
$checked =
empty($checked) &&
$option->checked ?
' checked' :
$checked;
$class =
!empty($option->class) ?
' class="' .
$option->class .
'"' :
'';
$disabled =
!empty($option->disable) ||
$this->disabled ?
' disabled' :
'';
// Initialize some JavaScript option attributes.
$onclick =
!empty($option->onclick) ?
' onclick="' .
$option->onclick .
'"' :
'';
$onchange =
!empty($option->onchange) ?
' onchange="' .
$option->onchange .
'"' :
'';
$html[] =
'<input type="checkbox" id="' .
$this->id .
$i .
'" name="' .
$this->name .
'" value="'
.
htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') .
'"' .
$checked .
$class .
$onclick .
$onchange .
$disabled .
'/>';
$html[] =
'<label for="' .
$this->id .
$i .
'"' .
$class .
'>' .
JText::_($option->text) .
'</label>';
// End the checkbox field output.
* Method to get the field options.
* @return array The field option objects.
foreach ($this->element->children() as $option)
// Only add <option /> elements.
if ($option->getName() !=
'option')
$disabled = (string)
$option['disabled'];
$disabled =
($disabled ==
'true' ||
$disabled ==
'disabled' ||
$disabled ==
'1');
$checked = (string)
$option['checked'];
$checked =
($checked ==
'true' ||
$checked ==
'checked' ||
$checked ==
'1');
// Create a new option object based on the <option /> element.
$tmp =
JHtml::_('select.option', (string)
$option['value'], trim((string)
$option), 'value', 'text', $disabled);
// Set some option attributes.
$tmp->class = (string)
$option['class'];
$tmp->checked =
$checked;
// Set some JavaScript option attributes.
$tmp->onclick = (string)
$option['onclick'];
$tmp->onchange = (string)
$option['onchange'];
// Add the option object to the result set.
Documentation generated on Tue, 19 Nov 2013 14:55:42 +0100 by phpDocumentor 1.4.3