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.

noResults message with search term

See original GitHub issue

I would like to show search term on noResults message. Is there any way to doing this?

Currently my code is like below, but it didn’t work:

$('#divId').select2(
    {
        language: {
             noResults: function(term) {
                 return "No results found. Add <b>" + term + "</b>?";
            }
        }
    }
);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
aekscocommented, May 4, 2016

I too think it would be helpful to either expose a noResults option on initialization that accepts either a string or a callback method that returns a string. For example:


// noResults option as a string
$('select').select2({
  noResults: 'No Users found.'
})

// noResults option as a function
$('select').select2({
    noResults: function(query) {
      return 'No results matching: ' + query;
    }
})

I’d be happy to put in a PR for this if I can get a go-ahead from a maintainer.

4reactions
ladrobcommented, Aug 29, 2017

If you would like to do some more stuff on selecting newly added tag:

$('select').select2({
    tags: true,
    insertTag: function(data, tag){
        tag.text = "Add: " + tag.text;
        data.push(tag);
    }	
}).on('select2:select', function(){
    if($(this).find("option:selected").data("select2-tag")==true) {
        // some more stuff...
    }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Searching by keyword returns no results even though the ...
Sometimes a keyword search returns no results, even though the keyword used exists in messages. To understand why this may happen, it's...
Read more >
50780 - The message "There are no results that match your ...
... 50780: The message "There are no results that match your search" occurs when there are special characters at the end of a...
Read more >
12 Awesome No Results Page Examples (+6 UI Design Best ...
The Best eCommerce No Results Page Examples. ... You don't have to over-complicate this: just tell them the search term they entered yielded...
Read more >
3 Guidelines for Search Engine "No Results" Pages
No Results pages must clearly state that no results have been found to match the user's search terms. Appropriate typography and spacing are ......
Read more >
Displaying message when no results returned JavaScript search
We have a JavaScript search script that pulls data from the Bing API. However, when no results are found for the users query, ......
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