Search code examples
javascriptjqueryajaxtwitter-bootstrapbootstrap-typeahead

How to search in bootstrap typehead after three characters?


I am using bootstrap-typehead.js, it will work like auto complete, in bootstrap-typehead it will search the result after one word, but I want to search it after three words.

This is my html code:

<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[&quot;Ahmedabad&quot;,&quot;Akola&quot;,&quot;Asansol&quot;,&quot;Aurangabad&quot;,&quot;Bangaluru&quot;,&quot;Baroda&quot;,&quot;Belgaon&quot;,&quot;Berhumpur&quot;,&quot;Calicut&quot;,&quot;Chennai&quot;,&quot;Chapra&quot;,&quot;Cherapunji&quot;]">

I want to search these words after three words.


Solution

  • You can use the option minLength (look at the doc : http://twitter.github.io/bootstrap/javascript.html#typeahead) :

    <input type="text" class="span3" style="margin: 0 auto;" data-min-length=3 .../>
    

    See this fiddle: http://jsfiddle.net/7JsTp/