Dude. I just tried something like this…
Sorry. I’m on the rush and can’t comment the code. Check if you can understand by yourself.
<?php echo $form->textFieldRow($model, 'zipcode', array('class'=>'span5', 'maxlength'=>10)); ?>
<?php echo $form->textFieldRow($model, 'address', array('class'=>'span5', 'maxlength'=>255)); ?>
<?php echo $form->textFieldRow($model, 'number', array('class'=>'span5', 'maxlength'=>10)); ?>
<?php echo $form->textFieldRow($model, 'complement', array('class'=>'span5', 'maxlength'=>150)); ?>
<?php echo $form->textFieldRow($model, 'neighborhood', array('class'=>'span5', 'maxlength'=>100)); ?>
<?php if($model->isNewRecord): ?>
<?php echo $form->dropDownListRow($model, 'country', CHtml::listData(Countries::model()->findAll(array('order'=>'name ASC')), 'id', 'name'), array('class'=>'span5', 'prompt'=>Yii::t('interface', 'Select one country'),
'ajax'=>array(
'type'=>'GET',
'url'=>$this->createUrl('suggestStates'),
'data'=>array('cid'=>'js:$(this).val()'),
'update'=>'#Properties_state',
'afterAjaxUpdate'=>'js:$("#Properties_state").attr("disabled", false)',
))); ?>
<?php echo $form->dropDownListRow($model, 'state', array(), array('class'=>'span5', 'disabled'=>'true', 'prompt'=>Yii::t('interface', 'Select one state'),
'ajax'=>array(
'type'=>'GET',
'url'=>$this->createUrl('suggestCities'),
'data'=>array('cid'=>'js:$("#Properties_country").val()', 'sid'=>'js:$(this).val()'),
'update'=>'#Properties_city',
'afterAjaxUpdate'=>'js:$("#Properties_city").attr("disabled", false)',
))); ?>
<?php echo $form->dropDownListRow($model, 'city', array(), array('class'=>'span5', 'disabled'=>'true', 'prompt'=>Yii::t('interface', 'Select one city'))); ?>
<?php else: ?>
<?php echo $form->dropDownListRow($model, 'country', CHtml::listData(Countries::model()->findAll(array('order'=>'name ASC')), 'id', 'name'), array('class'=>'span5', 'prompt'=>Yii::t('interface', 'Select one country'),
'ajax'=>array(
'type'=>'GET',
'url'=>$this->createUrl('suggestStates'),
'data'=>array('cid'=>'js:$(this).val()'),
'update'=>'#Properties_state',
'afterAjaxUpdate'=>'js:$("#Properties_state").attr("disabled", false)',
))); ?>
<?php echo $form->hiddenField($model, 'state', array('id'=>'state', 'name'=>'state')); ?>
<?php echo $form->dropDownListRow($model, 'state', array(), array('class'=>'span5', 'disabled'=>'true', 'prompt'=>Yii::t('interface', 'Select one state'),
'ajax'=>array(
'type'=>'GET',
'url'=>$this->createUrl('suggestCities'),
'data'=>array('cid'=>'js:$("#Properties_country").val()', 'sid'=>'js:$(this).val()'),
'update'=>'#Properties_city',
'afterAjaxUpdate'=>'js:$("#Properties_city").attr("disabled", false)',
))); ?>
<?php echo $form->hiddenField($model, 'city', array('id'=>'city', 'name'=>'city')); ?>
<?php echo $form->dropDownListRow($model, 'city', array(), array('class'=>'span5', 'disabled'=>'true', 'prompt'=>Yii::t('interface', 'Select one city'))); ?>
<?php Yii::app()->clientScript->registerScript(uniqid(), "
$(window).load(function(){
$.ajax({
type : 'GET',
url : '" . $this->createUrl('suggestStates') . "',
data : { cid: $('#Properties_country').val(), },
success : function (data) {
$('#Properties_state').html(data);
$('#Properties_state').val($('#state').val())
$.ajax({
type : 'GET',
url : '" . $this->createUrl('suggestCities') . "',
data : { cid: $('#Properties_country').val(), 'sid': $('#Properties_state').val() },
success : function (data) {
$('#Properties_city').html(data);
$('#Properties_city').val($('#city').val())
},
});
},
});
$('#Properties_state').attr('disabled', false);
$('#Properties_city').attr('disabled', false);
});
");
?>
<?php endif; ?>