CakePHP form helper - HABTM multiple checkbox styling
Asked Answered
C

3

5

I have two tables: "restaurants" and "cuisines" which are related to each other by a HABTM table

The table cuisines has certain fixed entries - 54 number

A restaurant can have any number of cuisines. On baking the application this came with a multiple select. Since i wanted check boxes i used array( 'type' => 'select', 'multiple' => 'checkbox') to convert it into checkboxes.

Now i want to style the way this checkboxes are displayed into columns of 4 as seen on the screenshot below.

img2.pict. com/82/bc/a4/1453459/0/200908111511.png

echo $form->input('Cuisine', array('type' => 'select', 'multiple' => 'checkbox'));  

The above code produces many div's around each element as follows

http://img2.pict.com/1a/a3/0a/1453457/0/200908121509.png

I have tried the following:

echo $form->input('Cuisine', array( 'type' => 'select', 'multiple' => 'checkbox', 'div' => false, 'label' => false));

but this code only removes the outside divs and label. I am not able to control the internal

<div class="checkbox">
<label for="CuisineCuisine2">Andhra</label>

that appear around the single checkboxes.

How can I use the FormHelper to remove or give classes to the internal divs, so I can do some custom styling? Or is there any other way to populate this HABTM table to get the effect i want?

Cormac answered 12/8, 2009 at 16:23 Comment(0)
P
4

You could get around this by doing $form->select() instead, and apply a style or class attribute to get it to look how you want.

It seems to make sense to not use the $form->input() function if you are going to remove the div and label anyway.

Pirate answered 13/8, 2009 at 21:2 Comment(0)
V
2

You can stylize the DIV elements with CSS.

<style>
div.input div.checkbox {
    float: left;
    width: 50%;
}
</style>
Venereal answered 28/8, 2009 at 5:39 Comment(0)
L
1

You can remove or give classes to the internal divs like this

$this->Form->input("hello_test",array('type'=>'checkbox','div'=>'class_name'));

By default cake uses : type class e.g - type is checkbox then class="checkbox"

Laina answered 23/8, 2012 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.