I have a view that is to be updated by a dropdownlist selection. This view also includes another dependent dropdown (id_types). Is there a straight forward way of doing this? I can use a renderPartial for the view update, but it does not update the dropdown selections?? If I use the dependent dropdown controller setting html options directly, I cannot update the view??
Thanks
Selection Dropdown:
<?php
echo CHtml::dropDownList('id_category', $assetData['category'], $assetData['categories'], array('prompt'=>'---Select---',
'ajax'=>array(
'type'=>'POST',
'url'=>yii::app()->createUrl('asset/AssetTypeData2'),
'data'=>array('category'=>'js:jQuery(this).val()'),
'update'=>'#type_list',
),
));
?>
Controller Action:
public function actionAssetTypeData2(){
$key = $_POST['category'];
$selected = '';
if(isset($_POST['selected'])){
$selected = $_POST['selected'];
}
$model = new AssetsForm();
$assetData['types'] = $model->getAssetTypes($key);
$assetData['type'] = $selected;
$this->renderPartial('/asset/_type', array('assetData'=>$assetData));
}
View to update:
<span id='type_list'>
<?php
echo CHtml::dropDownList('id_types', $assetData['type'], $assetData['types'], array('prompt'=>'---Select---',
'ajax'=>array(
'type'=>'POST',
'url'=>yii::app()->createUrl('asset/AssetAttributeData'),
'data'=>array('type'=>'js:jQuery(this).val()','timestamp'=>'js:jQuery("#h2_timestamp").val()'),
'update'=>'#attribute_list',
)));
echo CHtml::button('Add Type', array('onclick'=>"checkCategory('#dialogAddType');",
'id'=>'add_type','class'=>'assetControl1'));
echo CHtml::button('Delete Type', array( 'submit'=>array('asset/DeleteType'), 'class'=>'assetControl2',
'id'=>'del_type','confirm'=>'Are you sure?'));
echo CHtml::button('Edit Type', array('onclick'=>"checkCategory('#dialogModifyType')",
'id'=>'mod_type','class'=>'assetControl3'));
echo '<br/><br/></br>';
$this->renderPartial('/asset/_attribute', array('assetData'=>$assetData));
?>
</span>