Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 + typeahead.js 0.9.3. Prompt if no results found

Now that Bootstrap has dropped typeahead, they are recommending the native twitter typeahead (0.9.3 at the time of this writing)

I am having trouble finding examples of how to prompt the user when there are no results found.

In the native bootstrap, you could do this : http://bootply.com/61459

Perhaps this functionality is not possible?

like image 865
Nate Avatar asked Aug 15 '13 20:08

Nate


People also ask

What is typeahead bootstrap?

The typeahead input fields are very popular in modern web forms. The main purpose of using typeahead is to improve the user experience by supplying hints or a list of possible choices based on the text they've entered while filling a form or searching something — like the Google instant search.

What is typeahead dropdown?

To help a user make a selection in a long list, a dropdown typeahead shows suggestions as soon as the user starts typing.


1 Answers

How about something like this?

  $(document).ready(function() {
    $("#search").typeahead([
      {
        limit: 10,
        remote: {
          url: "//my.tld/gimmesomejson.php?searchuser=%QUERY",
          filter: function(parsedResponse) {
            var dataset = [];
            for (i = 0; i < parsedResponse.length; i++) {
              dataset.push({
                value: parsedResponse[i].value,
                tokens: parsedResponse[i].tokens
              });
            }
            if (parsedResponse.length == 0) {
              dataset.push({
                value: "No results" 
              });
            }
            return dataset;
          },
        },
        template: '<p>{{value}}</p>',
        engine: Hogan
      }
    ]);
  });
like image 116
Ian Avatar answered Oct 20 '22 17:10

Ian