Well, this is exactly what i have on my code and is not working.
Here is solution that worked in my case:
_form.php
<?php $form->widget('zii.widgets.jui.CJuiDatePicker',
array(
'model' => $model,
'attribute' => 'date',
'value' => $model->date,
'options' => array(
'showButtonPanel' => true,
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'placeholder'=>'yy-mm-dd',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('fighters/DynamicFighters'), //url to call.
'update'=>'#Matches_id_away', //selector to update
'data'=>array('date'=>'js:this.value', 'id_home'=>'js:$("#Matches_id_home").val()'),
),
),
));
?>
...
more code
...
<?php Yii::app()->clientScript->registerScript(uniqid(), "
id_away = $('#Matches_id_away').val();
$(window).load(function(){
$.ajax({
type : 'POST',
url : '" . $this->createUrl('fighters/DynamicFighters') . "',
data : { 'id_home': $('#Matches_id_home').val(), 'date': $('#Matches_date').val() },
success : function (data) {
$('#Matches_id_away').html(data);
$('#Matches_id_away').val(id_away);
},
});
});
");
?>
controller.php
public function actionDynamicFighters()
{
$homecrt= new CDbCriteria();
$homecrt->condition = 'id_fighter = :id_fighter
AND change_date <= :change_date';
$homecrt->params = array(':id_fighter'=>(int) $_POST['id_home'],
':change_date'=>$_POST['date']);
$homecrt->order = 'change_date DESC';
$home = FightersUpd::model()->find($homecrt);
if(!$home)
{
// Ia liga curenta din datele fighterului
$home = Fighters::model()->findByPk((int) $_POST['id_home']);
}
$away = Fighters::model()->with(array(
'fightersUpds' => array(
'alias' => 'f',
'select'=> 'id',
'condition' => 'f.change_date <= :change_date
AND f.stop_date > :stop_date
AND f.id_league = :id_league
AND f.id_fighter != :id_fighter',
'params' => array(
':change_date' => $_POST['date'],
':stop_date' => $_POST['date'],
':id_league' => (int) $home->id_league,
':id_fighter' => (int) $_POST['id_home']
))))->findAll(array(
'select'=> 'id,name,surname,id_league',
'order'=> 'name',
));
$away = CHtml::listData($away,'id','FullName');
echo '<option value="">= Select Away Fighter =</option>';
foreach($away as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
Hope it helps someone