Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show "No Results Found" with typeahead.js?

I am trying to show results not found message when there's no suggestion from user input. typeahead.js shows input suggestion while giving input to text field..if there no suggestion found then how to show results not found message?.. version is typeahead.js 0.11.1

like image 276
Muhammad Rizwan Avatar asked Feb 05 '23 08:02

Muhammad Rizwan


1 Answers

You can check if no result with empty parameter:

I have edited above code a little bit so that it may help to others searching the same thing.

$('.typeahead').typeahead({
    hint: false,
    highlight: true,
    minLength: 3,
},
{
    name: 'firstnames',
    displayKey: 'value',
    source: firstnames.ttAdapter(), // this is your result variable
    templates: {
        empty: function(context){
        //  console.log(1) // put here your code when result not found
          $(".tt-dataset").text('No Results Found');
        }
    }
like image 175
P. Frank Avatar answered Feb 07 '23 22:02

P. Frank