Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i prevent bootstrap typeahead from double filtering non-matching results from ajax call

I'm using bootstrap typeahead with a jQuery ajax which we will call FILTER#1. In my case, an ajax search like "great tank" or "greattank" both produce a "Great Tank" ajax result but typeahead is 2nd guessing my results and double filtering out (we will call FILTER#2) the second result because of the space. It is also possible that my ajax result back may be totally different than what was typed. I need typeahead to trust that the results provided were valid and display them regardless of an exact lowercase text match.

I'd like to have the following behavior:

  1. If there is a matching word in the results highlight it
  2. If there is a non-matching word display it unhighlighted but leave it in the result list vs. filtering it out.

(1) works OOTB, but (2) is the missing feature I'm looking for. If I can't have (1) and (2) I'd be ok with dropping (1).

Here is a fiddle example: http://jsfiddle.net/PE9mN/

        $("#title2").typeahead({
        source: function( request, response ) {
              var mockResults2 = ["Great Tank War", 
                                  "Great Train Robbery",
                                  "other random result my server produced"];
            response(mockResults2); 
            // I expect this to display both items regardless of $("#title2").val() 
            // In my case, the server was smart enough to realize that 
            // "greattank" may match "great tank"
            // and it even added a 3rd value that I want to display.
            }
           }); 

Thanks.

like image 395
JStark Avatar asked May 23 '13 17:05

JStark


1 Answers

If you add the following option to typeahead:

  matcher: function(item) {
      return true;
  }

Then no "second" filtering will apply.

like image 189
mccannf Avatar answered Oct 16 '22 17:10

mccannf