Yii Framework Forum: Yii Cjuiautocomplete Values Are Not Getting Displayed - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Cjuiautocomplete Values Are Not Getting Displayed Rate Topic: -----

#1 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 31 December 2012 - 10:24 AM

I apologise if this is already exists but i could not get it to work.. I need to show the names and store the id's in my table. these name are coming from other model(table). i'm getting the names and id's when i inspect elts in chrome network inspector.. but values are not not visible..but they are populating when i try to click on them its coming up in alert box with id..

can anyone pls help me to get names visible --thanks for ur help

my _form.php is something like this:



<div class="row">
        <?php echo $form->labelEx($typeModel,'benefit_type'); ?>
        <?php
    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'attribute'=>'name',
    'model'=>$typeModel,
    'sourceUrl'=>array('benefit/benefit_type_list'),
    'value'=>'Please select',
    'name'=>'name',
    'id'=>'id',
    'options'=>array(
        'minLength'=>'0',
         'select'=>"js:function(event, ui) {
     alert(ui.item.id);
                                        // $('#organisation_id').val(ui.item.id);
                                        }",
    ),
    'htmlOptions'=>array(
'id'=>'id',
    'size'=>45,
    'maxlength'=>45,
    ),
    )); ?>

    <?php echo $form->error($typeModel,'benefit_type'); ?>





extension class for getting the names and id's is:


 <? class EAutoCompleteAction extends CAction
    {
        public $model;
        public $attribute;
        public $id;
        private $results = array();
        public $returnVal = '';
        public function run()
        {
            if(isset($this->model) && isset($this->attribute)) {
                $criteria = new CDbCriteria();
                $criteria->compare($this->attribute, $_GET['term'], true);
                $model = new $this->model;
                foreach($model->findAll($criteria) as $m)
                {
                   // $this->results[] = $m->{$this->attribute};
                    //$this->results[] = $m-<{$this->id};
                    $this->results[] = array(
                        'name' => $m->{$this->attribute},
                            'id'=> $m->id
                    );



                    /* $this->returnVal .= $m->getAttribute('name').'|'
                    .$m->getAttribute('id'). "\n"; */
                }

            }

            echo CJSON::encode($this->results);
        }
    }
    ?>







and my Controller is some thing like this:


public function actions()
    {
        return array(
                'benefit_type_list'=>array(
                        'class'=>'application.extensions.EAutoCompleteAction',
                        'model'=>'BenefitType', //My model's class name
                        'attribute'=>'name', //The attribute of the model i will search
                ),
        );

    }




--any help would be highly appreciable


Thanks in advance
0

#2 User is offline   Kollipara Rama Krishna 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 12-May 12

Posted 02 January 2013 - 05:53 AM

http://www.yiiframew...complete-howto/

try this it may help you
0

#3 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 02 January 2013 - 10:06 AM

View PostKollipara Rama Krishna, on 02 January 2013 - 05:53 AM, said:

http://www.yiiframew...complete-howto/

try this it may help you



Thanks for the link
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users