10

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
  • 22,194
  • 16
  • 64
  • 99

1 Answers1

20

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.

.....

Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • @Nick: Oh, thats my typo. Sorry. But cross-checked with my code. All commas in place. – Robin Maben Nov 24 '10 at 10:06
  • 1
    @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... – Nick Craver Nov 24 '10 at 10:07
  • @Nick: Again, apologies. I dint know .ready() is deprecated. Does that play any role here? – Robin Maben Nov 24 '10 at 10:10
  • @conqenator - nope, using `1` instead of `0` is your root issue, but do fix the `.ready()` format none the less :) – Nick Craver Nov 24 '10 at 10:11
  • @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? – Robin Maben Nov 24 '10 at 10:19
  • @conqenator - Where is this `selectFirst` option coming from? http://jqueryui.com/demos/autocomplete/ it's not part of 1.8 at least, are you using a different version? – Nick Craver Nov 24 '10 at 10:21
  • @Nick: jQuery UI 1.8.5 - it's autocomplete. The docs are valid for this version? – Robin Maben Nov 24 '10 at 10:25
  • @conqenator - yes...not sure where you found that option, but it's not in the jQuery UI code... – Nick Craver Nov 24 '10 at 10:29
  • @Nick: I think it's there until 1.8.4. https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js – Robin Maben Nov 24 '10 at 10:37
  • @conqenator - that's an *extension*, not pat of jQuery UI itself, do you have that extension included? – Nick Craver Nov 24 '10 at 10:39
  • @Nick: Yes, I have it included. – Robin Maben Nov 24 '10 at 10:41