vendredi 17 juin 2022

How to create dynamic Checkboxlist in Yii?

I would like a help to solve this problem. I'm using Yii 1.1 and trying to create a dynamic CheckBox list in which its elements change depending on the value selected in a DropDown element.

I created this DropDown element with the arguments in Ajax to perform the function update in the Controller. The function in the Controller is doing the lookup in the table according to the value passed.

Up to this point, the code is working fine, generating an array with the values that should be displayed. The problem is that I'm not able to configure the return of these data and I can't even display them in the View.

Below is the code data:

View - DropDown element:

echo CHtml::activeDropDownList($model, 'standard',
                array(CHtml::listData(standard::model()->findAll(), 'name','name')),
                array('empty'=>'',
                    'ajax'=>array(
                    'type'=>'POST',
                    'url'=>CController::createUrl('/getTeam',array('form'=>'Team','field'=>'standard')),
                    'update'=>'#Audit_team'),
                )
            );?>

Controller:

public function actionGetTeam($form,$field) {
    $post = $_POST;
    $standard = $post[$form][$field];
    $Lists = TblAuditStandard::model()->findAll("standard = $standard");
    foreach ($Lists as $List){
       $AuditTeam[] = $List->name." - ".$List->login;     
       asort($AuditTeam);
       foreach ($AuditTeam as $id=>$value )
           echo CHtml::tag('option',array('value'=>$id),$value,true);
    }
}

View - Checkbox element:

<div class="row">
    <?php echo $form->labelEx($model,'team'); ?>
    <?php echo CHtml::activeCheckBoxList($model,'team',array()); ?>
    <?php echo $form->error($model,'team'); ?>
</div>

I hope someone can help me solve this problem. Thanks.




Aucun commentaire:

Enregistrer un commentaire