dependent dropdowns not working with activeDropDownList


I am new to YII. I am unable to get dependent drop downs work with CHTML::activeDropDownList. When the element name has [] in the name AJAX requests are not being made.

i.e <select id="Employee_customer" name="Employee[customer]">

If I use CHTML::dropDownList instead as per cookbook

I get validation error that field cannot be blank. This is happening because

Below the code in _form.php

<div class="row">

	&lt;?php echo CHtml::activeLabelEx(&#036;model,'customer'); 



	&lt;?php echo CHtml::activeDropDownList(&#036;model,'customer', &#036;custOptns, array('prompt'=&gt;'Please Select','ajax'=&gt;array('type'=&gt;'POST','url'=&gt;CController::createUrl('customerManager/fetchcustmgr'),'data'=&gt;'js:jQuery(this).serialize()','update'=&gt;'#Employee_project_manager')));


	&lt;?php echo &#036;form-&gt;error(&#036;model,'customer'); ?&gt;


&lt;div class=&quot;row&quot;&gt;

	&lt;?php echo CHtml::activeLabelEx(&#036;model,'project_manager'); ?&gt;

	&lt;?php echo CHtml::activeDropDownList(&#036;model,'project_manager',array()); 



	&lt;?php echo &#036;form-&gt;error(&#036;model,'project_manager'); ?&gt;


In Controller

public function actionFetchcustmgr()




	Yii::log(&quot;Value--&#62;&quot;.&#036;_POST['Employee_customer'], &quot;info&quot;, &quot;application.controllers.CustomerManagerController&quot;);



	foreach(&#036;data as &#036;value=&gt;&#036;name)



		Yii::log(CHtml::tag('option',array('value'=&gt;&#036;value),CHtml::encode(&#036;name),true), &quot;info&quot;, &quot;application.controllers.CustomerManagerController&quot;);


		echo CHtml::tag('option',




Anybody please help.

Basically, it is missing the ‘id’ attribute

<?php echo CHtml::activeDropDownList($model,'project_manager',array(), array('id' => 'Employee_project_manager' )); 



Note that when inserting code you can use the code directives so that your code is more readable… use [code ] inser your code here[/code ]… without spaces…

or the <> button in the toolbar

Thanks for the suggestion. I will use code directives.

Thanks for your reply.

When CHtml::activeDropDownList is used I see that it automatically creates the id & name attribute for the select element using model attribute. I have tried adding id attribute & name attribute but it does not work.

In the first place the 1st dropdown does not trigger ajax request when activeDropDownList is used. In the controller function actionFetchcustmgr() I have put a log statement. When I select a item in the dropdown it gets logged but I see nothing happens when activedropdownlist is used.

Everything works fine if I use dropdownlist. But I cannot submit the form since the validator throws value cannot be blank because it is expecting Employee[customer] to be the name of the select element.


i have the same problem,ajax doesnt triggs

Same problem here… Ajax doesn’t trigger

If anyone knows the solution, please post.

Can you post your non-working code?

Have you tried to debug (eg with Firebug) to see the generated jQuery code, and see whether it’s ever reached?

I’ve posted this on another forum (don’t want to be accused of spamming the boards, but here it is:

The _form code in question:

echo $form->dropDownList(






                                'ajax' => array(

                                    'type'=>'POST', //request type

                                    'url'=>CController::createUrl('getPractice'), //url to call.

                                    'update'=>'CoverageLine_PracticeCode', //selector to update







The Header of that form:

$form=$this->beginWidget('CActiveForm', array(





The calling controller function:

	public function actionUpdate($id)



		// Uncomment the following line if AJAX validation is needed












The Called Controller function:

        public function actionGetPractice()







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


                echo CHtml::tag('option',





I’d like to up this topic, because i’m still stuck whatever trick or tuts I could find on the web.

Do someone have some kind of a clue?

Thank you,