Hello,
I was able to create a dependant dropDownList, thanks to this tutorial: http://www.yiiframework.com/wiki/24/
However, I’d like 1st dropDownList to be multiselect. i.e. Second box will display cities that belong to 2 and more countries that were selected in the 1st box. Adding ‘multiple’=>‘multiple’ to options stops Ajax working at all(Firebug shows nothing). Any help is greatly appreciated
ps Controller will be changed to handle arrays. So never mind it for now. I was testing if ajax was working by simply printing ‘hello world’. It didn’t for ‘multiple’=>‘multiple’
Here’s the code if it is of any help:
view
$user = User::model()->findByPk(Yii::app()->user->id);
echo $dateForm->labelEx($datePickerModel, 'hospitalID');
echo $dateForm->dropDownList($datePickerModel, 'hospitalID', array(
CHtml::listData($user->hospitals, 'hospitalID', 'name')),
//array('multiple'=>'multiple', 'style'=>'width:200px; height:29px;'),
array('ajax'=> array(
'type'=>'POST',
'url'=>CController::createURl('site/dynamicLocations'),
'update'=>'#DatePicker_locationID'
))
);
echo $dateForm->errorSummary($datePickerModel);
?>
<?php
echo $dateForm->labelEx($datePickerModel, 'locationID');
echo $dateForm->dropDownList($datePickerModel, 'locationID',array());
echo $dateForm->errorSummary($datePickerModel);
?>
controller:
public function actionDynamicLocations()
{
$data = Location::model()->findAll('hospitalID=:parent_id', array(':parent_id'=>(int) $_POST['DatePicker']['hospitalID']));
$data = CHtml::listData($data, 'locationID','locationName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',array('value'=>$value), CHtml::encode($name),true);
}
}