jQuery autocomplete minLength
You have a few syntactical errors, the document.ready
handler is missing a brace (and is deprecated anyway) and a comma in your options, it should look like this:
$(function() {
$('#CompanyName').autocomplete({
source: companyNames,
select: SetLocations,
selectFirst: true, //here
minLength: 0
});
});
Also, autocomplete activates after minLength
characters, if you want it immediately, use 0
, from the docs:
minLength: The minimum number of characters a user has to type before the Autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.
.....
Comments
-
Robin Maben over 3 years
The autocomplete never fires on first character entered but 2nd. Although after using back-space it works for the minLength = 1. Also, the selectFirst:true never defaults to first item in the array on page load.
$().ready(function (){ $('#CompanyName').autocomplete({ source: companyNames, select: SetLocations, selectFirst :true, minLength: 0 //corrected as suggested, but still no change }); });
Has anybody faced this behavior before. I'm clueless since I haven't any global settings/defaults.
-
Robin Maben over 13 years@Nick: Oh, thats my typo. Sorry. But cross-checked with my code. All commas in place.
-
Nick Craver over 13 years@conqenator - make sure to post your actual code, when you just make up code for the question it makes it nearly impossible to answer...you've got at least 2 copy errors in there, a cut/paste shouldn't have this...
-
Robin Maben over 13 years@Nick: Again, apologies. I dint know .ready() is deprecated. Does that play any role here?
-
Nick Craver over 13 years@conqenator - nope, using
1
instead of0
is your root issue, but do fix the.ready()
format none the less :) -
Robin Maben over 13 years@Nick:Thanks for continuing to help with this. Upgraded to the new .ready() format. minLength: 0. Still, it fires at the 2nd character. And how would I go about setFirst:true. shouldn;t it set the value of the textbox on page load itself?
-
Nick Craver over 13 years@conqenator - Where is this
selectFirst
option coming from? jqueryui.com/demos/autocomplete it's not part of 1.8 at least, are you using a different version? -
Robin Maben over 13 years@Nick: jQuery UI 1.8.5 - it's autocomplete. The docs are valid for this version?
-
Nick Craver over 13 years@conqenator - yes...not sure where you found that option, but it's not in the jQuery UI code...
-
Robin Maben over 13 years@Nick: I think it's there until 1.8.4. github.com/scottgonzalez/jquery-ui-extensions/blob/master/…
-
Nick Craver over 13 years@conqenator - that's an extension, not pat of jQuery UI itself, do you have that extension included?
-
Robin Maben over 13 years@Nick: Yes, I have it included.