Sisko
(Cjaegle)
1
I have some problems with a dynamic list of checkboxes. I want to Update a list of checkboxes dependent on the dropdownlist.
I’ve tried something like that (and followed the Dropdown->Dropdown Article in Wiki):
View:
<?php
echo $form->dropDownList(
$model,
'item_id',
$model->getItems(),
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('controller/dynamicCheckBox', array('id'=>$id)),
'update'=>'#selector',
),
'prompt' => 'Select',
)
);
echo CHtml::CheckboxList(
'selector',
array(),
CHtml::listData(
Items::model()->findAll(),
'id',
'name'
),
)
);
?>
The action in the controller
public function actionDynamicCheckBox()
{
for ($i=0; $i<= count($wantedListOfItems)-1; $i++) {
//echo CHtml::checkBox('name', true, array('id'=>'selector_'.$i));
echo CHtml::tag('input',
array('checked'=>'checked','id'=>'selector_'.$i,'type'=>'checkbox'),false,true);
}
it outputs something on the console, which looks like the HTML code I want, but the Update of the existing checkboxes doesnt work.
I would be happy if you could help me.
teher811
(Thomas Roch)
2
In the API:
CheckBoxList Detail
You are specifying you want ‘#selector’ to be updated.
Your code generates a check box list with name ‘selector’, not id.
Add array(‘id’=>‘selector’) to your CheckBoxList! 
Sisko
(Cjaegle)
3
I can’t get it to work. Do you have a working example?
Maybe I should not render the checkboxlist in the first place, only after selecting in the dropdownlist.
Sisko
(Cjaegle)
4
I was frustrated, so I used <div> tags for grouping and update the <div> content. Less confusing for me 
smexo
(Smarcon2)
5
Hi.
I know it is an old post but I’m also trying to do a checkboxlist which depends of a dropdownlist and I don’t really understand how to do it. 
Have you created an empty <div> with the id ‘selected’? Or placed your checkboxlist inside a <div> with the id ‘selected’?
like this?
echo CHtml::CheckboxList(
'selector',
array(),
CHtml::listData(
Items::model()->findAll(),
'id',
'name'
),
array('id'=>'selector')
);
Thanks!