Permalink
Browse files

Have checkboxes read existing data and set checked options correctly.

  • Loading branch information...
1 parent d3432ab commit a6b59ba47e0b435f49a6cd89f29c98648c76933b @elinw elinw committed Jun 9, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 libraries/joomla/form/fields/checkboxes.php
@@ -51,6 +51,7 @@ protected function getInput()
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"';
+ $checkedOptions = explode(',',(string) $this->element['checked']);
// Start the checkbox field output.
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
@@ -62,9 +63,15 @@ protected function getInput()
$html[] = '<ul>';
foreach ($options as $i => $option)
{
-
// Initialize some option attributes.
- $checked = (in_array((string) $option->value, (array) $this->value) ? ' checked="checked"' : '');
+ if (empty($this->value))
+ {
+ $checked = (in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : '');
+ }
+ else
+ {
+ $checked = (in_array((string) $option->value, (array) $this->value) ? ' checked="checked"' : '');
+ }
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';

0 comments on commit a6b59ba

Please sign in to comment.