Yii Framework Forum: CAutocomplete - Yii Framework Forum

Jump to content

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

CAutocomplete Rate Topic: -----

#1 User is offline   Zahid Mughal 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-April 10
  • Location:Pakistan

Posted 20 May 2010 - 12:16 AM

halllo can any body tell me that how to submit value from the CAutocomplete when button is pressed...

My _form.php

<div class="row">
<?php $this->widget('CAutoComplete',array(
//name of the html field that will be generated

'name'=>'first_name',
'model'=>$model,


//replace controller/action with real ids
'url'=>array('patient_choices/autoCompleteLookup'),
'max'=>10, //specifies the max number of items to display

//specifies the number of chars that must be entered
//before autocomplete initiates a lookup
'minChars'=>1,
'delay'=>500, //number of milliseconds before lookup occurs
'matchCase'=>false, //match case when performing a lookup?

//any additional html attributes that go inside of
//the input field can be defined here
'htmlOptions'=>array('validateonsubmit' => TRUE,),

'methodChain'=>".result(function(event,item){\$(\"#referer_patient_id\").val(item[1]);})",
));
//echo CHtml::textField('referer_patient_id');
?>
<?php echo CHtml::textField('referer_patient_id'); ?>
</div>


My actionAutoCompleteLookup method in Controller

public function actionAutoCompleteLookup()
{
Yii::log('Auto Complete method call by : '.Yii::app()->user->id,'info','system.web.Patient_detailsController');
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 = "first_name LIKE :sterm";
$criteria->params = array(":sterm"=>"%$name%");
$criteria->limit = $limit;
//$model=$this->loadModel();
$userArray=patient_details::model()->findAll($criteria);
// $userArray = User::model()->findAll($criteria);
$returnVal = '';
foreach($userArray as $userAccount)
{
$returnVal .= $userAccount->getAttribute('first_name').'|'.$userAccount->getAttribute('id')."\n";
}

//$returnVal=$name;
echo $returnVal;
}
}
Zahid Mughal

0

#2 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 20 May 2010 - 07:22 AM

Check this:

Using CAutoComplete to display one value and submit another

Atencion is for 1.0.x, so may be, for 1.1.x needs some changes.

BTW, this is a spanish forum, you should not post in english here... please use the appropiate post for each thing...
Don't say what you think, think what you say
The problem is communication! Excess of communication!
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