Hi all,
I am trying to create dependent dropdown lists.
Society is the parent model
Apartment is the child to it.
In Apartment table i have 2 dropdowns
society_name(of society table)
block_name(of apartment table)
The value in block_name should be filtered based on the society_name selected.
In the controller i have written
public function actionDynamicstates()
{
$data = Society::model()->findAll('Society.society_name=:Apartment.society_name',
array(':Society.society_name'=> $_POST['Apartment']['Apartment.society_name']));
$data = CHtml::listData($Apartment,'block_name','block_name');
foreach($data as $id => $value)
{
echo CHtml::tag('option',array('value' => $id),CHtml::encode($value),true);
}
}
In _form i have written
<div class="row">
<td><?php echo $form->labelEx($model,'society_name'); ?></td>
<?php echo $form->labelEx($model,'Society'); ?>
<?php
$sdata = new CDbCriteria;
$sdata->order = 'society_name DESC';
?>
<td> <?php
echo $form->dropDownList($model,'society_name',CHtml::listData(Society::model()->findAll($sdata),'society_name','society_name'),
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('ApartmentController/dynamicstates'),
'update' => '#Apartment.block_name',
// 'success' =>'hai',
// 'error' =>'bai'
)
)
);
?></td>
<?php echo $form->error($model,'society_name'); ?>
</div>
Some how its not working. help me please