-
-
Save anonymous/f711330df558adc0ce7c to your computer and use it in GitHub Desktop.
initSelection for preselected select2 value
This file contains 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
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