typeahead - minLength to trigger the suggestion list

4094 views javascript
5

I set minLength to 3 to trigger the suggestion list when at least 3 characters have been typed in.

But the dropdown opens when 1 character is typed in. How to make this work?

$('#remote .typeahead').typeahead(null, {
  name: 'best-pictures',
  display: 'value',
  source: bestPictures,
  minLength: 3
});

Fiddle: https://jsfiddle.net/tomsx/bc6trhjk/

answered question

1 Answer

4

According to the document here - https://github.com/corejavascript/typeahead.js/blob/master/doc/jquery_typeahead.md#api, the first argument is options, it cannot be blank.

Change it to following and it should work,

$('#remote .typeahead').typeahead({minLength: 3}, {
  name: 'best-pictures',
  display: 'value',
  source: bestPictures,
});

posted this

Have an answer?

JD

Please login first before posting an answer.