Disable "No matches found" text and autocomplete on select2
Asked Answered
C

6

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.

Cadet answered 27/8, 2013 at 16:27 Comment(2)
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 of your non-working code so we have a starting point to help you solve your question.Daric
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.Leibniz
W
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.

Wiseman answered 28/8, 2013 at 20:42 Comment(3)
This is no longer valid in Select2 4.0, and there doesn't seem to be a way to do this.Demonize
@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: jsfiddle.net/8kRkc/59Wiseman
this will hide other select2 dropdown options if you have another select2 dropdown on pageAndrews
A
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

Adenocarcinoma answered 9/4, 2017 at 14:56 Comment(0)
G
3

For select2 4.0 you can do

.select2-results__message {
    display: none !important;
}
Gmt answered 14/1, 2016 at 20:0 Comment(0)
A
1
.select2-results {
     display: none;
 }

**Just override this **

Axel answered 23/10, 2015 at 6:47 Comment(0)
B
1

For select 2 4.0 you can do

$('#id').select2({
   minimumResultsForSearch: Infinity
});
Banket answered 4/3, 2016 at 1:48 Comment(0)
B
0

Version 4.0.13. You can do either one below code

.select2-results__message {
    display:none !important;
}

*OR*

li.select2-results__message {
    display:none !important;
}

*OR*

.select2-results .select2-results__message {
    display:none !important;
}
Badajoz answered 14/3 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.