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;
}
}