javascript 禁用“未找到匹配项”文本并在 select2 上自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18470917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable "No matches found" text and autocomplete on select2
提问by alexanoid
How do you disable the "No matches found" text on autocomplete on select2/Tagging Support?
如何在 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.
但它仍然在自动完成窗口中显示“未找到匹配项”消息。我想删除这个。
回答by Simon Adcock
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:
你可能可以在 CSS 中做到这一点:
.select2-no-results {
display: none !important;
}
Here's an example.
这是一个例子。
回答by razzbee
Actually I was using the select2 v4 tags and the code below helped me :
实际上我使用的是 select2 v4 标签,下面的代码帮助了我:
$(document).find(".email_contact_search").select2({
tags: true,
tokenSeparators: [','],
"language":{
"noResults" : function () { return ''; }
}
});
I just made the noResults lnaguage string to none :
我只是将 noResults 语言字符串设为 none :
"language":{
"noResults" : function () { return ''; }
}
Hope it helps someone
希望它可以帮助某人
回答by Diego Plentz
For select2 4.0 you can do
对于 select2 4.0 你可以做
.select2-results__message {
display: none !important;
}
回答by Ifta
For select 2 4.0 you can do
对于选择 2 4.0 你可以做
$('#id').select2({
minimumResultsForSearch: Infinity
});
回答by hasith wijerathna
.select2-results {
display: none;
}
**Just override this **
**只需覆盖这个**