jackal
(Supports2004)
March 30, 2011, 7:33am
1
Hello, in the docs we have such instruction:
http://www.yiiframework.com/doc/api/1.1/CAutoComplete#options-detail
options property
public array $options;
additional options that can be passed to the constructor of the autocomplete js object. This allows you to override existing functions of the autocomplete js class (e.g. the parse() function)
If you want to provide JavaScript native code, you have to prefix the string with js: otherwise it will be enclosed by quotes.
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?
rebus
(Nadirpaganini)
March 30, 2011, 7:50am
2
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.
krisd
(Kristof Dhalle)
March 30, 2011, 7:51am
3
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");}',
),
jackal
(Supports2004)
March 30, 2011, 10:20am
4
tried with “js:” also , doesn’t work…
tri
(tri - Tommy Riboe)
March 30, 2011, 10:45am
5
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
jackal
(Supports2004)
March 30, 2011, 10:56am
6
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");}}'),