In addition to @vararis answer:
Select2, attached to the <select> element, does not allow you to use the custom functions createSearchChoice and query , so we will need to manually add the option element (I will add it as the last variant of the element so that we can easily .pop from the result set):
<select> ... <option value="0">Other</option> </select>
Then pass the matcher custom function matcher that this Other option is always mapped.
NOTE. Select2 3.4+ uses a different default resolver than the one currently shown in the documentation, this new one has a call to stripDiacritics , so that a matches á , for example. Therefore, I’ll apply the default matcher , which comes with the version of Select2 included in the page, to apply my default matching algorithm to any option, and not to the Other option:
matcher: function(term, text) { return text==='Other' || $.fn.select2.defaults.matcher.apply(this, arguments); },
Finally, we need to remove the “Other” parameter from the result set when there is a result other than the “Other” result (which is always in the result set):
sortResults: function(results) { if (results.length > 1) results.pop(); return results; }
source share