ActiveCheckBoxList has Unexpected Behavior

I have been playing around with the checkboxes to become familar with it so My page has multiple instances of the activeCheckBoxList with variances in each. When in the view, if any of the items below item1 are selected then item1 gets checked or unchecked. I have tried setting each differently, however nothing corrects this behavior.

I have not seen any documentation which states that only one instance can be in a view, so maybe I am just not doing it right for such circumstances. I can post some code if needed.

Can anyone explain?

don’t be too clear your depiction :lol: ; you can look at the generated html code , and notice the “name” attribute of your checkBoxs . if they affect each other the “name” attribute( i don’t know if “id” also has effect) may be the reason . better give your code here .

Okay, I found a solution so that each instance will check and uncheck only it’s self.

HOWEVER, I am not sure that it is a good solution or if it is a set up for more problems. I am too new to this stuff to see consequinces ahead, So it would be great to get insight now.

Here is a sample of correctly working code, the first two instances of activeCheckBoxList on the page. It was the $attribute which needed to be unique to each instance. So in the model I made up unique variables, which have no relation to the db table and now it works fine.




/* variables in the model - one for each instance 1-19 */

public $itemName1;

public $itemName2;

public $itemName3;


// The view file...


<TR>

<TD headers="t1">


<?php echo CHtml::activeCheckBoxList($model, 'itemName1', 

        CHtml::listData(serviceItemSelect::model()->findAllbySql(

                'SELECT itemId, CONCAT(itemId, ". ", itemName) as itemData FROM serviceItemSelect WHERE itemId=1'

                ), 'itemId', 'itemData'),

        array('template'=>'{input} {label}')

);

?>

</TD>

<TD headers="t2">item1 description</TD>

<TD headers="t3">item1 timeEst</TD>

<TR>

<TD headers="t1" class="itemname">


<?php echo CHtml::activeCheckBoxList($model, 'itemName2', 

        CHtml::listData(serviceItemSelect::model()->findAllbySql(

                'SELECT itemId, CONCAT(itemId, ". ", itemName) as itemData2 FROM serviceItemSelect WHERE itemId=2'

                ), 'itemId', 'itemData2'),

        array('template'=>'{input} {label}')

);

?>


</TD>

<TD headers="t2">item2 description</TD>

<TD headers="t3">item2 timeEst</TD>


<TR>

Hi clicken,

One variant is to use checkBoxList to enter your custom name - it’s a better approach then to create new properties needed only for one case.

Second variant is to use idea form this article in yii-guide.

Please also notice in provided code you’re making the same sql queries several times, it’s better to form checkboxes list in your controller and then to pass variable with this list to a view.

Regards

The tabular input looks like something I can use, I have bookmarked that link, thanks. I do have several tables which will be used for a single task.

For now I am trying things, to see how they look and to help me understand. I have never done any php until I found yii. So this is all good exercise.

I find the views easier to manage while testing and trying to find what will work best for my application. When I find the methods that work best then things can be set in the controller and models. I dont want to clutter them up because it would be difficult for me, newbie, to sort out a mess.

What I discovered is that due to the long list in my table the checkbox takes up too much room on the page. Whether it is an all-in-one or multiple instances. The only way that I can think of to get all of the info into the limited space with checkbox is to have the itemNames with the box and a message type window on mouseover for the descriptions. But that sounds like a big bite for me to chew as a beginner.

I may have to settle for a listBox even though it isn’t what I originally planned, until I get more experienced. I am trying it out and am working on errors. If I had a nickle for every error message I’ve seen, I wouldn’t need to do a website! LOL, it is such gratification when it works!

Your input is greatly appreiciated Yugene, I hope to see more off it.

Thanks.

You’re on the right way making it step by step ;)