How I did it:
<div class="form-group"> <label class="control-label">Destination</label> <input type="text" name="cdCountry" class="form-control" required /> </div> <script> $("[name='cdCountry']").select2({ placeholder: "Select a country", formatResult: function (country) { return $( "<span><i class=\"flag flag-" + country.id.toLowerCase() + "\"></i> " + country.text + "</span>" );; }, data: yourDataSource }); </script>
and using the css library (css and sprite) https://www.flag-sprites.com/
source share