Select2: how to add a link instead of the text "No results"?

Below is my code:

$('#cow_id_2').select2({ allowClear: true, placeholder: "Search a cow/dam ID", formatNoMatches: function (term) { return "<a href=/'http://google.com/'>Add</a>"; } }); 

When I try to add a link, the plugin just stops working. I am using Select2 version 4.0.3

+1
source share
1 answer

If you are using version 4 or later select2, try the following:

 $('#cow_id_2').select2({ allowClear: true, escapeMarkup: function (markup) { return markup; }, placeholder: "Search a cow/dam ID", language: { noResults: function () { return "<a href=/'http://google.com/'>Add</a>"; } } }); 
+4
source

All Articles