I am using Select2 Version 3.5.2 and need to trigger a custom message if my AJAX result length is greater than x. How can you trigger a custom message which I can handle in the same way like given messages formatting messages (formatLoadMore, formatSelectionTooBig, ...).
Asked
Active
Viewed 1,861 times
1 Answers
2
Override formatResult and implement a custom behaviour. Eg. for a special property in your resultset (result.error):
function formatResult(result, container, query, escapeMarkup) {
var markup = [];
if(result.error != undefined && result.error) {
markError(result.text, markup);
} else {
Select2.util.markMatch(result.text, query.term, markup, escapeMarkup);
}
return markup.join("");
};
special format:
function markError(text, markup) {
markup.push("<b style='color: red;'>");
markup.push(text);
markup.push("</b>")
};

trollr
- 1,095
- 12
- 27