Skip to content

Instantly share code, notes, and snippets.

/select2_config.js Secret

Created May 8, 2014
Embed
What would you like to do?
initSelection for preselected select2 value
initSelection: function(element, callback) {
var id=$(element).val();
if (id!=="") {
$.ajax("/countries/"+id+".json", {
dataType: "json"
}).done(function(data) {
var selected = {id: element.val(), text: data.name + " (" + data.country_code + ")"};
callback(selected);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment