October 14, 2015
Select2 drop-down for countries, with flags
Delavnog’s Question:
I was working on a similar problem and here is how I solve it.
(function($) {
$(function() {
var isoCountries = [
{ id: 'AF', text: 'Afghanistan'},
...
];
//Assuming you have a select element with name country
// e.g. <select name="name"></select>
$("[name='country']").select2({
placeholder: "Select a country",
data: isoCountries
});
});
})(jQuery);
I also have made a gist about it and following are the demos.