Hi,
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 http://www.yiiframework.com/wiki/24/
I get validation error that field cannot be blank. This is happening because
Below the code in _form.php
<div class="row">
<?php echo CHtml::activeLabelEx($model,'customer');
$custOptns=Customer::model()->fetchCustomers();
?>
<?php echo CHtml::activeDropDownList($model,'customer', $custOptns, array('prompt'=>'Please Select','ajax'=>array('type'=>'POST','url'=>CController::createUrl('customerManager/fetchcustmgr'),'data'=>'js:jQuery(this).serialize()','update'=>'#Employee_project_manager')));
?>
<?php echo $form->error($model,'customer'); ?>
</div>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'project_manager'); ?>
<?php echo CHtml::activeDropDownList($model,'project_manager',array());
?>
<?php echo $form->error($model,'project_manager'); ?>
</div>
In Controller
public function actionFetchcustmgr()
{
$data=CustomerManager::model()->findAll('tbl_customer_idcustomer=:id_cust',array(':id_cust'=>$_POST['Employee_customer']));
Yii::log("Value-->".$_POST['Employee_customer'], "info", "application.controllers.CustomerManagerController");
$data=CHtml::listData($data,'idcustomer_mgr','first_name');
foreach($data as $value=>$name)
{
Yii::log(CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true), "info", "application.controllers.CustomerManagerController");
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
Anybody please help.