admin管理员组

文章数量:1328584

I am using jQuery autoplete. Here is my
HTML

<input class="autoplete_input">  

JS

$(".autoplete_input").autoplete({
    source: autopleteOptions
});

// autopleteOptions is a array which contains all values for autoplete

Everything is working fine. I want to dispaly all suggestions on onFocus. After some Googling and reading some similar questions on SO I found the minChars property of Autoplete. I tried but still no luck

$(".autoplete_input").autoplete({
    source: autopleteOptions,
    minChars:0
});      

How can I use minChars correctly?

EDIT1:
I am using this link. Thank you Rory.
On given link I couldnt find minLength property.
EDIT2:
I tried

 $(".autoplete_input").autoplete({ minLength: 0, source: autopleteOptions});

Still suggestions are not displayed on onFocus. One difference I noticed is if I type any char then corresponding results are displayed and if I delete that char using backslash then all suggestions are displayed.

I am using jQuery autoplete. Here is my
HTML

<input class="autoplete_input">  

JS

$(".autoplete_input").autoplete({
    source: autopleteOptions
});

// autopleteOptions is a array which contains all values for autoplete

Everything is working fine. I want to dispaly all suggestions on onFocus. After some Googling and reading some similar questions on SO I found the minChars property of Autoplete. I tried but still no luck

$(".autoplete_input").autoplete({
    source: autopleteOptions,
    minChars:0
});      

How can I use minChars correctly?

EDIT1:
I am using this link. Thank you Rory.
On given link I couldnt find minLength property.
EDIT2:
I tried

 $(".autoplete_input").autoplete({ minLength: 0, source: autopleteOptions});

Still suggestions are not displayed on onFocus. One difference I noticed is if I type any char then corresponding results are displayed and if I delete that char using backslash then all suggestions are displayed.

Share Improve this question edited Jan 9, 2012 at 12:36 Ajinkya asked Jan 9, 2012 at 11:37 AjinkyaAjinkya 22.7k33 gold badges112 silver badges163 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 4

Are you using jQuery UI Autoplete?

The correct parameter would be minLength

$( ".selector" ).autoplete({ minLength: 0, source: autopleteOptions });

Assuming this is the plugin you're using, try this:

$(".autoplete_input").autoplete(
    autopleteOptions,
    { minChars: 0 }
});   
/*
 * jQuery Autoplete plugin 1.2.3
 *
 * Copyright (c) 2009 Jörn Zaefferer
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource/licenses/mit-license.php
 *   http://www.gnu/licenses/gpl.html
 *
 * With small modifications by Alfonso Gómez-Arzola.
 * See changelog for details.
 *
 */

in line 588 change this 

[[[ for (var i = q.length - 1; i >= options.minChars; i--) {   ]]]

for this 

[[[ for (var i = q.length - 1; i >= 0; i--) {   ]]]

Try to use focus event and call autoplete showing manually:

$(".autoplete_input").autoplete({
    source: autopleteOptions
}).focus(
    function() {
        if (this.value == "") {
               $(this).autoplete('search', '');
            }
        }
    );

Here is the documentation page for jQuery autoplete: http://jqueryui./demos/autoplete/

The option you're looking for is minLength

$(".autoplete_input").autoplete({
source: autopleteOptions,
minLength:0
});      

set minchars: 0; make below changes in your autoplete.js file.

Inside "window.opera" add a click event like shown below

this.el.click(function () {
  e.onClick();
}),

and add this function after "onValueChange"

onClick: function () {
   var ae = this.getQuery(this.currentValue);
   if(ae.length < 1){
      this.onValueChange();
   }
},

look for "onValueChange" function and in there replace the return argument as shown below

//return (this.selectedIndex = -1), this.ignoreValueChange ? void (this.ignoreValueChange = !1) : void ("" === e || e.length < this.options.minChars ? this.hide() : this.getSuggestions(e));

return (this.selectedIndex = -1), this.ignoreValueChange ? void(this.ignoreValueChange = !1) : void (this.getSuggestions(e));

本文标签: javascriptAutocomplete minChars propertyStack Overflow