xyz xyz - 7 months ago 39
Javascript Question

Autocomplete minChars property

I am using jQuery autocomplete. Here is my

HTML

<input class="autocomplete_input">


JS

$(".autocomplete_input").autocomplete({
source: autocompleteOptions
});

// autocompleteOptions is a array which contains all values for autocomplete


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 Autocomplete. I tried but still no luck

$(".autocomplete_input").autocomplete({
source: autocompleteOptions,
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

$(".autocomplete_input").autocomplete({ minLength: 0, source: autocompleteOptions});


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.

Answer

Are you using jQuery UI Autocomplete?

The correct parameter would be minLength

$( ".selector" ).autocomplete({ minLength: 0, source: autocompleteOptions });