retrieve value in CAutoComplete in update mode

Hi,

I have a doubt in CAutoComplete widget…

i hv a table "feespaid" with three fields

1.date

2.enrollment_id

3.amount

here enrollment id is foreign key which is retrieved from table "course" course table has

1.enrollment_id

2.enrollment_no

in my view i hv a CAutoComplete widget for enrollment_id which is used to show enrollment_no from course table.




  <?php $this->widget('CAutoComplete', array(

                    'model'=>$model,

                    'name'=>CHtml::activeName($model, 'enrollment_id'),

                    'minChars'=>2,

                    'max'=>100,

                    'url'=>array('feesPaidDetails/autoCompleteLookup'),

                    'htmlOptions'=>array('size'=>'50'),

                    'methodChain'=>".result(function(event,item)

                            {\$(\"#enrollment_id\").val(item[1]);

                                })",

                    )); ?>

                <?php echo $form->hiddenField($model,'enrollment_id',array('id'=>'enrollment_id')); ?>



in my controller




 public function actionAutoCompleteLookup()

    {

       if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))

       {

            /* q is the default GET variable name that is used by

            / the autocomplete widget to pass in user input

            */

          $name = $_GET['q'];

       // this was set with the "max" attribute of the CAutoComplete widget

          $limit = min($_GET['limit'], 50);

          $criteria = new CDbCriteria;

          $criteria->condition = "enrollment_no LIKE :sterm";

          $criteria->params = array(":sterm"=>"%$name%");

          $criteria->limit = $limit;

          $course = CourseEnrollment::model()->findAll($criteria);

          $returnVal = '';

          foreach($course as $courseRecord)

          {

             $returnVal .= $courseRecord->getAttribute('enrollment_no').'|'

                                         .$courseRecord->getAttribute('enrollment_id')."\n";

          }

          echo $returnVal;

       }

    }	



it works well in creation…

my problem is i dont know how retrieve the enrollment no in CAutoComplete widget in update mode…

please help me

try with something like:




  <?php $this->widget('CAutoComplete', array(

                    'model'=>$model,

                    'name'=>CHtml::activeName($model, 'enrollment_id'),

                    'value'=>($model->enrollment0)?$model->enrollment0->enrollment_no:'',




This should work well in update

thanks… it works really well…

what is en

enrollment0?? where do you define it??