How To Populate Checkboxlist With Ajax

Hello,

i have a drop downlist which display a list of value. The list of value is alway the same.

But it not every time the same values that are checked.

dropdownlist




  <?php echo $form->dropDownListRow($model, 'fk_form_groupe_id', $listeFormGroupes, array('class'=>'span4','id'=>'formGoupeId','prompt' => Yii::t('view', '[tousConcernes]'), 'tabindex' =>5,

             'ajax' => array(

                            'type' => 'POST',

                            'dataType' => 'json',

                            'url' => Controller :: createUrl('/DfcPosteHasFormGroupe/majCkListPoste'),

                            'data' => array('fkFormGroupe' => 'js:this.value'),

                            'success' => 'function(data) {     

                              

                                    $("#listPostesId").val(data.listePostes);

                                }'

                        ),));

        ?>



checkboxlist




 <div id="formGroupeDiv" style="display:none">

            <?php echo $form->checkBoxList($model, 'listPostes', $listePostes, array('id'=>'listPostesId','tabindex' => <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />); ?>

        </div>



my code in my controller :




 public function actionMajCkListPoste() {


        if (Yii::app()->request->isAjaxRequest) {


            $fkFormGroupe = $_POST['fkFormGroupe'];

            $listePostes = DfcPosteHasFormGroupe::findAllPostes($fkFormGroupe);

          // list postes return a array => {"listePostes":["6","8","9","10","52","53","54","55","62"]}

            

            echo CJSON::encode(array(

                'listePostes' => $listePostes,

            ));

        }

    }



I would like that the check boxes list show which value coresponding to the value in the dropdownlist are int the database.

any ideas?

Nath

Up !

Did it populate your CheckBoxList ? Because in my case it doesn’t work …