Your problem can be splitted in 2 parts:
A very simple method is this one:
Let’s put a div among the ddl, just for make the stuff easy. In your view you will have:
<div class="row">
<?php echo $form->labelEx($model,'field'); ?>
<div id="divForDddl"><?php echo $form->dropDownList($model,'field', array(...)); ?></div>
<?php echo $form->error($model,'field'); ?>
</div>
Just a div more.
Now, in case of success, in the controller we will return a new dropDownList, with selected the new value:
if (Yii::app()->request->isAjaxRequest)
{
$mainModel = new MyMainModel;
$mainModel->field= $model->primaryKey; // let's select the newly created value
echo CJSON::encode(array(
'status'=>'success',
'ddl'=>CHtml::ActiveDropDownList($model, 'field', array(...)) // a ddl with the value already selected!
));
exit;
}
This should send the whole dropdownList, with the new value in list (because we generate the ddl after saving the model) and with the value selected (we set this value in the model before generate the ddl).
Now we have to change the js as follows:
if (data.status == 'failure')
{
$('#dialogClass div.divForForm').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#dialogClass div.divForForm form').submit(addClass);
}
else
{
$('#divForDddl').html(data.ddl);
}
In case of success, we replace the content of the divForDddl (that contains only a ddl) with the ddl we sent.
I didn’t tested anything, so be careful!
P.S: welcome to the forum