Search code examples
javascripttypeahead.jstypeaheadbootstrap-typeaheadtwitter-typeahead

Typeahead only showing the exact match. How can I show all the data that is returned from remote url.?


I am facing a problem that I want to implement a search in which if you type the string with the double quotes("") it must also work.

Example: apple and "apple" both must return the same result

When I make the call to the backend, the call for both the search query is retuning the same thing but the typeahead filters the data somehow and the data does not get displayed in case of "apple".

I have tried using the filters like dropDownFilter and filter by assigning them false:

$('#searchInput').typeahead({ minLength: 1, order: "asc", delay: 500, 
                              dynamic: true, groupMaxItem: 6, highlight: false, 
                              hint: true, group: ["{{group}}, kind"], 
                              dropdownFilter: false,

But its not working, can anyone suggest me something.

Any help will be appreciated.!


Solution

  • Try providing your own matcher function. Something along the lines of:

    $('.typeahead').typeahead({source:myarray, matcher: function(item){
        // the regular expression will (optionally) consider double-quotes
        var reg = new RegExp('"?'+this.query+'"?');
    
        if( item.match(reg) ){
            return true;
        }else{
            return false;
        }
     }});