Skip to content

Instantly share code, notes, and snippets.

@phuonghuynh
Created January 13, 2015 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phuonghuynh/b9dcc9fa652f2e962f33 to your computer and use it in GitHub Desktop.
Save phuonghuynh/b9dcc9fa652f2e962f33 to your computer and use it in GitHub Desktop.
Useful configuration for Select2 component
$(".searchText").select2({
width: "100%",
tags: tags, // => tagging support, allow use add new entry
tokenSeparators: [" "], // => to separate entries
formatSelection: instance.function (item) {
if (item.id === item.text) {
return "<div style='height: 16px;'>" + item.text + "</div>";
}
return "<img style='width: 16px; height: 16px;' src='images/" + item.logo + "'> " + item.text + " </img>";
}, // => "on select" : useful to handle "unidentified" entry (should return new tag)
formatResult: instance.formatItem, // => "after select" : useful to handle "unidentified" entry (should return new tag)
createSearchChoice: function (text) { // => find suitable tag
var tag = utils.findBy(tags, "text", text);
if (tag === undefined) {
tag = {id: text, text: text};
}
return tag;
},
createSearchChoicePosition: "bottom",
placeholder: "Enter to search...",
openOnEnter: false,
escapeMarkup: function (markup) { return markup; }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment