dependent dropDownList and empty options

Hi,

I have 3 dropdownlists. Things work fine, but I would like to have an "empty" option tag at the begining of each list.

Scenario I would achieve is

An item is selected in list 1

Then list 2 is populated and the "empty" option tag is only visible. When click on this list, then all options tags are shown. (as usual)

But I am unable to have the empty option tag, because with ajax, when my list is populated then empty option tag is removed.

Is there a way to achieve this ?

Thanks

OK,

I solved my problem by adding this empty option in the server response. And I do not use prompt or empty options of dropDownList


     public function actionDynamicVersions() {

         $data = AdminVersion::model()->findAll('modele_id=:modele_id',

                        array(':modele_id'=>(int) $_POST['AdminVoiture']['modele_id']));




        $data = CHtml::listData($data,'id','nom');

        echo CHtml::tag('option',array('value' => ''),'Choose one version...',true);

        foreach($data as $id => $value)

            {

                echo CHtml::tag('option',array('value' => $id),CHtml::encode($value),true);

            }

     }

But I have another problem

My dropDownLists are linked (dependent) Update of their content works fine 2 by 2. I mean I update list 1 then list 2 is updated, I updated list 2 then list 3 is correctly updated.

But When I change list 1, then I would appreciate that both list 2 and list 3 are updated (list 3 would contain only the empy option tag…

Do you know how to do this ?

Thanks

In the first List I try to use the ‘success’ field. I expected that when Ajax request is a success then this method is used.

In this method I empty the list 3.

It works for emptying the list 3 but I think it overwrites the ‘update’ field because in my list 2 no update is made


		<?php echo $form->dropDownList(

            $model,

            'marque_id',

            CHtml::listData(AdminMarque::model()->findAll(),'id','nom'),

            array(

               'ajax'=>array(

                    'type'=>'post',

                    'url'=>CController::createUrl('voiture/dynamicModeles'),

                    'update'=>'#AdminVoiture_modele_id',

                    'success'=>'

                        function() {

                            $("#AdminVoiture_version_id").empty();

                        }

                    '

                    

                ),

                'prompt' => 'Choisissez une marque'

            )


           ); ?>

Then I do not know how to clean up this list 3 when changes occur in the list 1

I just would like to know whether I may use the ajax facilities (I mean the update stuff) embbeded in drodDownList or Shall I program myself the ajax update (meaning populating the differnt list according to my need ( 3 dependent lists ) )

Thanks

OK, I get the solution.

I do not know whether this solution is the best one, nevertheless it works fine for me.

I have 3 lists. They are dependent but they have to see as cascade, then importance of each depends of their order.

When list 1 is updated then list 2 AND list 3 must be updated. List 2 with result of the Ajax request and List 3 must be cleaned up.

When List 2 is updated List 3 must be updated with Ajax request result.

My solution is that in the List 1 dropdownlist I do not use the ‘update’ field which is just intended to update the List 2

I write this in the List1’s dropdownList


'ajax'=>array(

                    'type'=>'post',

                    'url'=>CController::createUrl('voiture/dynamicModeles'),

                    'success'=>'

                        function(data) {

                            $("#AdminVoiture_modele_id").empty().append(data);

                            $("#AdminVoiture_version_id").empty().append("<option>Choisissez une version</option>");

                        }

                    '

#AdminVoiture_modele_id is the id of the List 2

#AdminVoiture_version_id is the id of the List 3

All things work fine with that