mercredi 24 février 2016

CakePHP 3 - Form Select Option Group - Multiple Checkboxes

First, I've successfully implemented a Multiple Select box with option groups based on providing an providing a group of options structured like this:

$options = [
   'Group 1' => [
      'Value 1' => 'Label 1',
      'Value 2' => 'Label 2'
   ],
   'Group 2' => [
      'Value 3' => 'Label 3'
   ]
];
echo $this->Form->select('field', $options);

This is straight from the Cookbook at: http://ift.tt/1OhBL7S

It works great, and makes a select box exactly as it should. My issue is that I would like to change the display to be multiple checkboxes. In order to do that, I've switched the code to:

echo $this->Form->input('field', [
        'multiple' => 'checkbox',
        'options' => $options
    ]);

When I do this, the display ends up being a single checkbox, with all the options listed out next to it.

In searching stackoverflow, I found the following: How to create multiple checkboxes grouped by fieldsets in Cakephp 3

Most seem to indicate that the functionality is not included in Cake, and that you need to build it on your own. There is one comment on the initial question that references the cookbook and that it specifically states:

If you would like to generate a select with optgroups, just pass data in hierarchical format. This works on multiple checkboxes and radio buttons too, but instead of optgroups wraps elements in fieldsets:

No one seems to address the comment on that question. My question is really simple. Does CakePHP 3 allow for multiple checkboxes created as outlined in the documentation, or is the documentation incorrect and this functionality isn't included in the core? If the answer is that the functionality is included in the core, what's the trick to getting it to work?

Thanks!




Aucun commentaire:

Enregistrer un commentaire