I have several dropdownlist which are working like charm except when there are preselect values passed from the controller to the form so much so that the form will be render with the preselected values in each dropdown. This how i have passed the variables in the controller
public function actionBodyTrim(){
$trim = new CarTrim;
$spares = new Spares;
$spares->makeid = $_REQUEST['mid'];
$spares->modelid = $_REQUEST['moid'];
$spares->bodyid = $_REQUEST['bid'];
$spares->trimid = $_REQUEST['tid'];
$this->render('bodytrim', array(
'trim'=>$trim,
'spares'=>$spares
)
);
}
When the form is rendered the first dropDownList is displaying the pre-selected value from the controller. But all the other dropDownlist are not working. Actually on the view the second dropDownList show the raw Ajax code, meaning the Ajax is not firing correctly. The result is shown below
<div class="span5 leftpull">
<div class="row">
<div class="width125"><?php echo $form->labelEx($model,'makeid'); ?></div>
<div class="widthtxt"><?php echo $form->dropDownList($model,'makeid', CHtml::listData(Makes::model()->findAll(array('order' => 'makename ASC')), 'makeid', 'makename'),
array('prompt'=>'Select Makes',
'ajax'=>array('url'=>CController::createUrl('CarModels'),
'beforeSend' => 'function(){$("#carmodels").addClass("loading");}',
'complete' => 'function(){$("#carmodels").removeClass("loading");}',
'type' =>'POST',
'update'=>'#'. CHtml::activeId($model, 'modelid'),
array('class'=>'ajaxlink'),
))); ?>
<?php echo $form->error($model,'makeid'); ?>
</div>
</div>
<div class="row" id="carmodels">
<div class="width125"><?php echo $form->labelEx($model,'modelid'); ?></div>
<div class="widthtxt"><?php echo $form->dropDownList($model, 'modelid', empty($model->modelid) ? array('prompt' => 'Select the country first') :
array('ajax'=>array('type'=>'POST',
'url'=>CController::createUrl('BodyType'),
'update'=>'#'. CHtml::activeId($model, 'bodyid'),
'prompt'=>'Models',
array('class'=>'ajaxlink'),
)));
?>
<?php echo $form->error($model,'modelid'); ?>
</div>
</div>
Below is the HMTL code of the form with the Ajax function showing as values of the dropdown not firing as required.
<div class="row" id="carmodels">
<div class="width125"><label for="Spares_modelid" class="required">Model <span class="required">*</span></label></div>
<div class="widthtxt"><select name="Spares[modelid]" id="Spares_modelid">
<optgroup label="ajax">
<option value="type">POST</option>
<option value="url">/spareparts/index.php?r=spares/parts/BodyType</option>
<option value="update">#Spares_bodyid</option>
<option value="prompt">Models</option>
<optgroup label="0">
<option value="class">ajaxlink</option>
</optgroup>
</optgroup>
</select> </div>
</div>
I know the problem is more likely on the view but i can’t point my finger on the issue. I appreciate you response in advance.