Thanks for replying, mdomba. Anyway, here what I do:
I have 2 parts (models) in category page. The main part (form) and detail part. Category detail part consists of several information and CGridView to display data that related to main category. Users can add detail items via form that is rendered in CJuiDialog. After data is saved, dialog should be automatically closed and the detail part of page should be refreshed (via Ajax).
<h1>Update Category</h1>
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?> // this is the main form
<div id="category-detail"> // detail part
<?php $this->renderpartial('/categoryDetail/create', array('model'=>$detailModelCreate)); ?>
</div>
In view categoryDetail/create :
<?php
// CGridView is rendered in this view
$this->renderpartial('/categoryDetail/admin', 'model'=>$model);
$this->beginWidget('zii.widgets.jui.CJuiDialog', array('id'=>'distributorFormDialog'));
?>
<div id="divForForm">
<?php $this->renderpartial('/categoryDetail/_form',array(
'model'=>$model,
'categoryId'=>$categoryId
)); ?>
</div>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
<script type="text/javascript">
// refresh detail page
function refreshDetail() {
<?php echo CHtml::ajax(array(
'url'=>array('categoryDetail/create', 'categoryId'=>$categoryId),
'update'=>'#category-detail',
))?>;
}
</script>
Finally, here is how ajax submit button looks in ‘categoryDetail/_form’:
echo CHtml::ajaxSubmitButton( 'Add', $url, array(
'success'=>'js: function(data) {
if (data == "Success") {
// close dialog and refresh detail page if data is successfully saved
$("#distributorFormDialog").dialog("close");
refreshDetail();
}
else
// display the form if validation failed
$("#divForForm").html(data);
}'
),
array('id'=>'addItem' .uniqid())
);
Besides the delete confirmation that appears twice, I also notice that CJuiDialog cannot be closed after Ajax refresh. Perhaps I do something wrong here?
P.S. I’m sorry if this becomes a long post
, but I’ve truncated them as much as I can.