Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set at least two characters in jQuery UI autocomplete?

I am using jQuery autocomplete and would like to limit the showing results only when the user types at least 2 characters. How to do that?

like image 408
Derfder Avatar asked Jun 19 '12 17:06

Derfder


1 Answers

for the record:

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.

Code examples

Initialize a autocomplete with the minLength option specified.

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

Get or set the minLength option, after init.

//getter
var minLength = $( ".selector" ).autocomplete( "option", "minLength" );
//setter
$( ".selector" ).autocomplete( "option", "minLength", 0 );

minLengthIntegerDefault:1

docs

like image 96
chrisvillanueva Avatar answered Oct 21 '22 10:10

chrisvillanueva