Ajax refresh of cActiveForm

Hi

I am using the following javascript to refresh a gridview via ajax


		

$.fn.yiiGridView.update("gridProfileSegmentList", {

 type:"POST",

 data: "pid=" + obj.pid,

 url: "ajaxUpdateSegmentGrid",

});



The controller ajax function looks like this




public function actionAjaxUpdateSegmentGrid() {


 $pid = Yii::app()->getRequest()->getParam('pid');


 $dataProviderExistingSegments=new CActiveDataProvider('LoadProfileSegment', array(

  'criteria'=>array(

  'condition'=>'ProfileID=' . $pid,

  'order'=>'SegmentNo',

 ),));


 $this->renderPartial('_segmentGrid',array(

  'dataProviderExistingSegments'=>$dataProviderExistingSegments,

 ));


}



The partial _segmentGrid contains the gridview widget only. This all works fine.

My question is…is it possible to do the same or a similar thing with a CActiveForm. I have the form widget in a partial just as the grid is and would like to be able to make an ajax call from javascript so that the form model is ‘refreshed’ and populated with new values from this model.

Thanks

tb

Take a look at this wiki.

thanks zaccaria…in the end I solved it with a new controller function




public function actionAjaxClearSegmentForm() {

 $modelProfileSegment = new LoadProfileSegment;


 $this->renderPartial('_segmentForm',array(

  'modelProfileSegment'=>$modelProfileSegment,

 ));


}



and the following js call (using jq ui dialog directly)




$.ajax({ // reset segment form

  url: "ajaxClearSegmentForm",

  success: function(data){

   $("#segmentDialog").html(data);

   $("#segmentDialog").dialog("open");

  }

});



this js is the first thing run when the dialog that contains the form is displayed and seems to give me what i want…thanks again for the help

And what if the input insterted is not correct?

Does it work correctly? My wiki allows you to stay in the dialog until the input is correct.

hi…I intend that the form will have ajax validation so that as focus moves from a field it will be checked against the model rules. I have not put this in yet but have another form which does that and it seems to work okay, proper testing to be done and validation to be added in today! That should ensure that the input is correct. I will take a closer look at your wiki though as I was unaware of the CJuiDialog class - I am used to using jQ UI dialog directly and am interested to see how the wrapper works and what advantages it offers.

cheers

The biggest advantage with the wrapper is that you will have the url translation authomatically.