I'm trying to allow only one value within select2 library, no matter how it's written. For example if the value "Test" is in the data list, "test" should not be added again. I've searched for a while and also looked at the documentation, but I didn't solve this one.
$("#timezones").select2({
tags: true,
createTag: function (tag) {
return {
id: tag.term,
text: tag.term + " (new)",
isNew: true
};
},
matcher: function (term, data) {
// `term.term` should be the term that is used for searching
// `data.text` is the text that is displayed for the data object
if ($.trim(term.term) === '') {
return data;
}
var termString = term.term.trim();
var textString = data.text.trim();
var termStringUpper;
var textStringUpper;
if (termString) termStringUpper = termString.toUpperCase();
if (textString) textStringUpper = textString.toUpperCase();
return termStringUpper == textStringUpper;
}
});
Here is one JSFiddle: https://jsfiddle.net/2sz0oj8m/