Ticket Details

when use 'checkbox-multi', Lithium does not set 'checked' automatically.

ENHANCEMENT Ticket (pending)

###when use 'checkbox-multi', Lithium does not set 'checked' automatically.

In the template file, I used 'checkbox-multi' like below.

{{{
<?=$this->form->field(
'hobby', 
array(
      'type' => 'checkbox-multi', 
      'value' => 'pc', 
      'label' => 'pc', 
      'template' => 'field-checkbox')); 
?>
// output
// <input type="checkbox" name="hobby[]" value="pc" /><label for="hobby" value="Array">CakePHP1.1</label>
}}} 

And after posting data, I wanted it to set 'checked' value automatically if it is checked.
But the represented HTML is like bellow.

{{{
// not checked.
// <input type="checkbox" name="hobby[]" value="pc" /><label for="hobby" value="Array">CakePHP1.1</label>
}}} 

If I wrote the code like this, I could set 'checked' value but it is inconvenience.

{{{
<?=$this->form->field(
'hobby', 
array(
      'type' => 'checkbox-multi', 
      'value' => 'pc', 
      'label' => 'pc', 
      'checked'=> (is_array($question['hobby']) && in_array($v, $question['hobby']))? true: false,
      'template' => 'field-checkbox')); 
?>
}}}

###期待していた事:
So, I wrote the patch like this.

{{{
diff --git a/libraries/lithium/template/helper/Form.php b/libraries/lithium/template/helper/Form.php
index 360d276..975e1aa 100644
--- a/libraries/lithium/template/helper/Form.php
+++ b/libraries/lithium/template/helper/Form.php
@@ -521,6 +521,9 @@ class Form extends \lithium\template\Helper {
                if ($hasValue) {
                        $options['value'] = $value;
                }
+               if ($method === "checkbox-multi" &&is_array($this->_binding->$name) && in_array($options['value'], $this->_binding->$name)) {
+                       $options['checked'] = true;
+               }
                if (isset($options['default']) && empty($options['value'])) {
                        $options['value'] = $options['default'];
                }
}}}

I'm afraid of not understanding the core code, but it is seemed to run correctly.
on 09.19.10 reported by: brtriver

Updates