question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No results found option

See original GitHub issue

I know that I can specify an empty template for each dataset, but I have 6 or 7 datasets and I would like to specify something to be displayed when none of the datasets have hits.

If I just type in “4q8nywrfxm”, I don’t want to see 6 datasets all saying that they can’t find that text, I just want one message, specified at the typeahead level (not the dataset level).

Does that make sense?

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:4
  • Comments:27 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
jmhmdcommented, Oct 5, 2016

Thanks @lucaspiller and @atrain0789

Here’s another approach building on the snippet from @lucaspiller:

const emptyMessage = `<div class="empty-message">
    No matches found.
  </div>`;
const emptyMessageNode = $(emptyMessage);
// hide empty message by default
emptyMessageNode.hide();
// get menu element and append hidden empty messsage element
const menuNode = $('.typeahead.tt-input').data('tt-typeahead').menu.$node;
menuNode.append(emptyMessageNode);

$('.typeahead').on('typeahead:asyncreceive', function () {
  if ($(this).data('tt-typeahead').menu._allDatasetsEmpty()) {
    // hide dataset result containers
    menuNode.find('.tt-dataset').hide();
    // show empty message and menu
    emptyMessageNode.show();
    menuNode.show();
  } else {
    // show dataset result containers
    menuNode.find('.tt-dataset').show();
    // hide empty message
    emptyMessageNode.hide();
  }
});
4reactions
murph133commented, Nov 2, 2017

I think I’ve found a simple solution for only showing one empty template, when working with multiple datasets.

1. Add an empty template to one dataset If you only want to show the message when ALL are empty, you only need to add one message.

templates: {
    empty: '<div class="empty-message">No results</div>'
}

2. Add event trigger keyup for the typeahead input field (.tt-input)
We don’t want to show an empty message is a suggestion from another dataset. So whenever there is more than 0 suggestions, we hide the empty-message.

$(document).on('keyup', ".tt-input", function() {

    if($(".tt-suggestion").length){
        $(".empty-message").hide();
    }

});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you modify "No Results Found" language in Select2 ...
The option noMatches doesn't appear anywhere in the source code. The actual option is named noResults. The working version of your example ...
Read more >
No results found in all select fields - Development - Select2
“No results found” means that the current search term doesn't match any of the available options. So the other think I can think...
Read more >
Select2 No Results Found Button - CodePen
1. /* Expand button to all of option */ ; 2 .select2-results__option.select2-results__message { ; 3. padding: 0px; ; 4. } ; 5. button#no-results-btn...
Read more >
Is there a way to customize/style the "No results found ... - GitHub
You can return a jQuery element $() from that as well if you want some custom HTML. This appears to be more of...
Read more >
Always get 'No results found' with ajax option - Google Groups
I'm trying to dynamically load the select2 options using the ajax feature but I keep getting the 'No results found' error even though...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found