<?php echo $form->dropDownList(
$model,
'HomeState',
CHtml::listData(HomeState::model()->findAll(),'StateCode','StateName'),// no need to start array here, as CHtml::listData() returns array
array(// start array here
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('getCity'), //url to call.
'update'=>'#Address_CityCode', //selector to update
'data'=>array('HomeState'=>'js:this.value'),
)
)
));
?>
Should send request with these fixes.
And please check out all details for dropDownList function
Again… Thank you, very helpful. However… AJAX is still not firing. I know this same problem is posted on another forum, but I’m guessing I’m doing something wrong in setting up the AJAX.
In the actionUpdate function of the controller, I’ve uncommented the line:
Simplify problematic code, leaving only essential lines of code and provide it here (controller, view, layout) - everything I need to reproduce the feature, as the first example with provided fixes works just fine in my test environment.
I placed a regular HTML drop down list on the form, which works fine:
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('CoverageLine/GetPractice'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#Coverageline_PracticeCode', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)));
The problem I’m having seems to be with CActiveForm. When I place the same logic within a CActiveForm element:
echo $form->dropDownList(
$model,
'CommodityCode',
array(
CHtml::listData(Commodity::model()->findAll(),'CommodityCode','CommodityName'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('CoverageLine/GetPractice'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#Coverageline_PracticeCode', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)
)
)
);
In the CActiveForm version, it fires the form->Update instead of the form->GetPractice, and the GetPractice never gets fired…