Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery autocomplete minLength

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.

like image 397
Robin Maben Avatar asked Nov 24 '10 10:11

Robin Maben


1 Answers

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.

.....

like image 156
Nick Craver Avatar answered Nov 15 '22 16:11

Nick Craver