8

How do you disable the "No matches found" text on autocomplete on select2/Tagging Support?

This is what I have now:

$('#ProductDescriptions_30_keywords').select2({
        tags:[],
        tokenSeparators: [",", " "],
        minimumResultsForSearch: -1
        }
    );

But it still shows the "No matches found" message in autocomplete window. I would like to remove this.

Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • There is not enough information for this to qualify as a question. Please take the time to write a clear question, and post your code. It would be very helpful if you also provide a [jsFiddle example](http://jsfiddle.net) of your non-working code so we have a starting point to help you solve your question. – cssyphus Aug 27 '13 at 16:31
  • 1
    Unless the question has since been updated, it has more than adequate information (especially as I was looking for an answer to the exact same question). Thanks @simonadcock for the solution. – Ted Apr 25 '14 at 23:57

5 Answers5

12

I think I see what you're getting at... You want to hide the text that says "No matches found" if a user enters a value into that search field that doesn't exist in the list?

You can probably do that in CSS:

.select2-no-results {
    display: none !important;
}

Here's an example.

Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
  • This is no longer valid in Select2 4.0, and there doesn't seem to be a way to do this. – guidod Aug 07 '15 at 19:33
  • @guidod: It's a bit of a hack, but you could build a selector that exploits the fact that the "No results found" `li` does not have an `id` attribute: http://jsfiddle.net/8kRkc/59/ – Simon Adcock Aug 14 '15 at 11:36
  • this will hide other select2 dropdown options if you have another select2 dropdown on page – Saurabh Solanki Jan 31 '19 at 05:52
10

Actually I was using the select2 v4 tags and the code below helped me :

 $(document).find(".email_contact_search").select2({
    tags: true,
    tokenSeparators: [','],
    "language":{
      "noResults" : function () { return ''; }
    }
  });

I just made the noResults language string to none :

"language":{
          "noResults" : function () { return ''; }
        }

Hope it helps someone

Big Zak
  • 1,040
  • 12
  • 17
3

For select2 4.0 you can do

.select2-results__message {
    display: none !important;
}
Diego Plentz
  • 6,760
  • 3
  • 30
  • 31
1
.select2-results {
     display: none;
 }

**Just override this **

1

For select 2 4.0 you can do

$('#id').select2({
   minimumResultsForSearch: Infinity
});
Ifta
  • 1,536
  • 18
  • 25