Created
January 13, 2015 06:22
-
-
Save phuonghuynh/b9dcc9fa652f2e962f33 to your computer and use it in GitHub Desktop.
Useful configuration for Select2 component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".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