CheckBoxList Index

Is it possible to get the index value of the current CheckBoxList item?

For example:


<?php echo $form->checkBoxList($model, 'category', $categories_list, array('data-id' => $index)); ?>

In the above, $index should automatically output the numerical index of the current item in the loop.

the expression below is wrong you can’t set the data-id on select from the list

as current CheckBoxList item/index changes on each iteration


<?php echo $form->checkBoxList($model, 'category', $categories_list, array('data-id' => $index)); ?>

// output of this will be 

<select data-id="1">

...

</select>

It is a checkboxlist, not a SELECT.

Output should be:


<input type="checkbox" name="Product[category][]" value="1" data-id="0" />

<input type="checkbox" name="Product[category][]" value="2" data-id="1" />

<input type="checkbox" name="Product[category][]" value="3" data-id="2" />

my bad did not notice that you could try it with jquery.