Yii 1.1: jqautocomplete

Ajax Powered Autocomplete Plugin for Yii -JQuery.js
11 followers

This extension is a wrapper to use my own creation of Ajax Powered Autocomplete. Please, refer to my website to get a detailed description of this plugin.

Requirements

I have created this extension using the latest Yii but can be used from Yii 1.0 and above.

Usage

Unzip the file and:
1. copy jqAutocomplete.php and jqautocomplete folder to your application's protected/extensions folder.
2. copy test.php to your application's protected/views folder
3. copy TestController.php to your application's protected/controllers folder
4. copy test_layout.php to your application's protected/layouts folder

to run the test just do http://yourapplicationurl/index.php?r=test/autocomplete

Look at the view and you will see something like this:

Yii::import('ext.jqAutocomplete');
 
$json_options = array(
    'script'=> $this->createUrl('test/json',array('json'=>'true','limit'=>6)) . '&',
    'varName'=>'input',
    'shownoresults'=>true,
    'maxresults'=>16,
    'callback'=>'js:function(obj){ $(\'#json_info\').html(\'you have selected: \'+obj.id + \' \' + obj.value + \' (\' + obj.info + \')\'); }'   
);
 
// #test_json is your text field id 
// (please refer to the example view page for the field wrap)
jqAutocomplete::addAutocomplete('#test_json',$json_options);

Resources

Total 11 comments

#9745 report it
chikazaki at 2012/09/07 11:10pm
If you need multiple input field...

then you must create multiple instances.

use

protected static function create($selector, $options = array(), $position = CClientScript::POS_END){
       self::registerScript();
       $options = CJavaScript::encode(CMap::mergeArray(self::defaultOptions(),$options));
 
       Yii::app()->clientScript->registerScript(__CLASS__.$selector, 'var jq = new $.autoComplete("'.$selector.'",'. $options.');', $position);
    }

instead

protected static function create($selector, $options = array(), $position = CClientScript::POS_END){
       self::registerScript();
       $options = CJavaScript::encode(CMap::mergeArray(self::defaultOptions(),$options));
 
       Yii::app()->clientScript->registerScript(__CLASS__.$selector, 'JQuery.autoComplete("'.$selector.'",'. $options.');', $position);
    }
#7557 report it
dcmouser at 2012/03/29 11:35pm
Thank you for sharing!

Thank you for sharing this.. took me a bit to get it working but it works well. Though i'm still looking to figure out why it breaks when there are 2 on a page.

#5627 report it
Antonio Ramirez at 2011/10/26 11:23am
@tomwittkower

"Permission denied", that is not an issue with the widget but with your security settings.

#5510 report it
tomw at 2011/10/17 03:54pm
error

I followed the instructions but get:

require(C:\xampp\htdocs\protected\controllers\TestController.php) [function.require]: failed to open stream: Permission denied

#3176 report it
R.K. at 2011/03/24 05:39am
array merge 2 times

fix for comment of code.

protected static function create($selector, $options = array(), $position = CClientScript::POS_END){
    self::registerScript();
    $options = CJavaScript::encode(CMap::mergeArray(self::defaultOptions(),$options));
 
    Yii::app()->clientScript->registerScript(__CLASS__.$selector, 'jQuery.autoComplete("'.$selector.'",'. $options.');', $position);
}
 
public function addAutocomplete($selector, $opts = array()) {
 
    self::create($selector, $opts);
}
#3175 report it
R.K. at 2011/03/24 05:36am
array merge 2 times

i noticed that there was 2 times merge, i think that it will be wise to have like this.

[code] protected static function create($selector, $options = array(), $position = CClientScript::POS_END){ self::registerScript(); $options = CJavaScript::encode(CMap::mergeArray(self::defaultOptions(),$options));

    Yii::app()->clientScript->registerScript(__CLASS__.$selector, 'jQuery.autoComplete("'.$selector.'",'. $options.');', $position);
}

public function addAutocomplete($selector, $opts = array()) {

    self::create($selector, $opts);
}

[/code]

#2706 report it
Bibi40k at 2011/01/31 06:55am
example

could you please help me with an example to search for letters no matter their position inside a word and how to search for a name and submit id instead ?

Thank you

#2704 report it
Antonio Ramirez at 2011/01/31 06:27am
@Bibi40k

The search server PHP script is just an example, you can modify it to suit your needs.

#2701 report it
Bibi40k at 2011/01/31 02:12am
question

looks like only knows to search sequential ?

#2413 report it
Antonio Ramirez at 2010/12/27 10:52am
@ tpthanx

Trying to fix it. Thanks for your report.

#2197 report it
Tuan Phan at 2010/11/24 05:17am
Does not work with 2 or more fields

I have tried with two fields (as belown) with two script url and it still make request to the first url. Please help to fix this.

Yii::import('ext.jqautocomplete.jqAutocomplete');
 
$json_options = array(
        'json' => true,
    'script'=> $this->createUrl('/organization/autocomplete',array('json'=>'true','limit'=>6)) . '&',
    'varName'=>'input',
    'shownoresults'=>true,
    'maxresults'=>16,
    'callback'=>'js:function(obj){ $(\'#Person_organization_id\').val(obj.id); }'
);
jqAutocomplete::addAutocomplete('#Person_orgName',$json_options);
 
$json_options = array(
        'json' => true,
    'script'=> $this->createUrl('/person/autocomplete',array('json'=>'true','limit'=>6)) . '&',
    'varName'=>'input',
    'shownoresults'=>true,
    'maxresults'=>16,
    'callback'=>'js:function(obj){ $(\'#Person_father_id\').val(obj.id); }'
);
jqAutocomplete::addAutocomplete('#Person_fatherName',$json_options);

Leave a comment

Please to leave your comment.

Create extension