mercredi 1 juin 2016

Cakephp set default value for multiple checkbox subgroups

How to set default selected checkboxes when using "sub-groups" of checkboxes? You can achieve the so-called "sub-groups" by having a nested array for 'options' attribute. I want to have all checkboxes selected by default.

echo $this->Form->input('fooBar', [
    'type' => 'select',
    'multiple' => 'checkbox',
    'label' => false,
    'class' => 'inlineBlock',
    'options' => [
        'Foo' => [0 => 'Yes', 1 => 'No' ]
        'Bar' => [0 => 'One', 1 => 'Two', 2 => 'Three']
]]);

I've tried by setting

'selected' => [0 => [0, 1], 0 => [0, 1, 2]]

and

'checked' => true

but no luck. If I check them manually and than submit the form, Cakephp generates URL parameters as if there were no "sub-groups", e.g.:

'options' => [0 => 'Yes', 1 => 'No' ]

which is the same behaviou as if I set

'default' => [1, 2, 3]

Is it even possible to set selected checkboxes of individual checkbox "sub-groups"?




Aucun commentaire:

Enregistrer un commentaire