This my form 3143
. Only when I choose a different value in the State Dropdown the dependent dropdown works. What if the user wants the first value itself? Then he won’t be able to choose the City.
What’s a work around. My view file.
<div class="row">
<?php echo $form->labelEx($model,'stateId'); ?>
<?php echo $form->dropDownList($model,'stateId',CHtml::listData(State::model()->findAll(), 'id', 'name'), array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('city'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#cityId', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
))); ?>
<?php echo $form->error($model,'stateId'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'cityId'); ?>
<?php echo CHtml::dropDownList('cityId','', array()); ?>
<?php echo $form->error($model,'cityId'); ?>
</div>