HTML formatting for checkBoxList()

By default the checkBoxList generates a default formatting, I want it to generate custom formatting as follows:

(for each checkbox:)




<tr>

    <td class="label"><label for="index">value</label></td>


    <td><input type="checkbox" id="index" /></td>

</tr>



Can anyone help me with this please?

Is this what you want to do? (The generated attributes ar still the same)




echo CHtml::checkBoxList('...','...', array(...),

  array('template'=>'<tr><td >{label}</td><td>{input}</td></tr>')

);



/Tommy

Cheers mate, that’s done the job perfectly.

Anybody know how can I split this checkBoxList and display it in two columns (side by side)? Is there any function in Yii that can do this?

Did anyone figure out how to display the checkboxlist as two columns?

Thanks

Two columns? You mean something like:

label checkbox

label checkbox

label checkbox

or

label checkbox label checkbox

label checkbox label checkbox

label checkbox label checkbox

?

Your second example.

I kind of figured out how to do it, I had to use a foreach loop and generate the checkboxes manually. So in other words I was unable to do it using the checkBoxList method. It would have been nice if there was a built in functionality in Yii to acheive this.

This is the direction I went in as well.

I think there is no need to achieve that using checkBoxList. CheckBoxList is simply a list. You have template option to modify standard template and that’s it. If you need to achieve something different you build your own solution using single checkbox. In my opinion this is the best way to keep it simple.

Hmm well I like to keep things simple, but I think the Yii CheckBoxList should have something that allows for multiple columns.

Or at least get rid of the last "<br />" after each checkbox so we can float them left.

You can get rid of those '<br />'s by specifying ‘separator’ option like this




echo CHtml::checkBoxList('...','...', array(...),

  array(

    'separator'=>'',

    )

);



Example of Pronskiy’s & JamesBarnsley’s advice:


<div class="checkboxgroup">

<?php 

	echo CHtml::checkBoxList('...','...', array(...),

	  array(

	    'separator'=>'',

	    'template'=>'<div>{input}&nbsp;{label}</div>'

	    )

	);	

?>

</div>


<style>

.checkboxgroup{

	overflow:auto;

}

.checkboxgroup div{

	width:200px;

	float:left;

}

</style>

Hello guys,

I am trying to use checkboxlist, but it inserts all the labels and inputs into a span. How can I remove that span ?

Kind Regards,

Marian