Search code examples
javascripttypeahead.jsbloodhound

typeahead - minLength to trigger the suggestion list


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/


Solution

  • 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,
    });