I am trying to use the yii autocomplete build in widget. I have manage to show results from my users table intro the input filed with the following blocks of code:
public function actionSearch()
{
$res =array();
if (isset($_GET['term']))
{
$qtxt ="SELECT user FROM tbl_user WHERE user LIKE :user";
$command =Yii::app()->db->createCommand($qtxt);
$command->bindValue(":user", '%'.$_GET['term'].'%', PDO::PARAM_STR);
$res =$command->queryColumn();
}
echo CJSON::encode($res);
Yii::app()->end();
}
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1',
'source'=>$this->createUrl('user/search'),
// additional javascript options for the autocomplete plugin
'options'=>array(
'showAnim'=>'fold',
'select'=>'js:function( event, ui ) {
//
}'
),
));
As soon as a user is selected i want to redirect to that user page. I need to catch the user name in the select event. Or an alternative way is to catch both the user name and the user id to be able to easily redirect on that id.
I hope this is a solution
'select' => 'js:function( event, ui ){
// ui.item.id
// ui.item.name
top.location = "/user/view/?id=" + ui.item.id;
}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With