CAutoComplete , 'options' param

Hello, in the docs we have such instruction:

http://www.yiiframework.com/doc/api/1.1/CAutoComplete#options-detail

Unfortunatelly there is no some example how to use this param…

I want to override function hideResultsNow() in jquery.autocomplete.js and trying to do this in such way:




                <?php $this->widget('CAutoComplete', array(

                        'model' => $model,

                        'attribute' => 'city',

                        'url' => array('suggestCity'),

                        'mustMatch' => true,

                        'minChars'  => 3,

                        'htmlOptions' => array('size'=>50),

                        'options'=>array(

                              'hideResultsNow'=>'function(){ alert("a");}',


    ),

                )); ?>



but old function hideResultsNow() works . What is wrong?

Try:

‘hideResultsNow’=>‘js:function(){ alert(“a”);}’,

Note: If you want to provide JavaScript native code, you have to prefix the string with js: otherwise it will be enclosed by quotes.

Haven’t tested it but I think you have to prepend the javascript code with ‘js:’. Like this:




'options'=>array(

  'hideResultsNow'=>'js:function(){ alert("a");}',

),



tried with “js:” also , doesn’t work…

According to the source code a fixed set of properties/functions are supported. hideResultsNow is not one of them. (The CAutoComplete class is deprecated.)




protected function getClientOptions()

{

  static $properties=array(

    'minChars', 'delay', 'cacheLength', 'matchSubset',

    'matchCase', 'matchContains', 'mustMatch', 'selectFirst',

    'extraParams', 'multiple', 'multipleSeparator', 'width',

    'autoFill', 'max', 'scroll', 'scrollHeight', 'inputClass',

    'formatItem', 'formatMatch', 'formatResult', 'highlight',

    'resultsClass', 'loadingClass');

  static $functions=array('formatItem', 'formatMatch', 'formatResult', 'highlight');

  ...

}



Since the method is protected an inherited class that overrides getClientOptions may be an option.

/Tommy

after reading http://docs.jquery.com/Plugins/Autocomplete it seems I got it.

it must be in a such format:




                'options'=>array(

                              'extraParams'=>'js:{hideResultsNow:function(){ alert("a");}}'),