Skip to content

Instantly share code, notes, and snippets.

@oliveiraxavier
Created July 13, 2022 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliveiraxavier/9cc3bda4ac898f455935917aef0b55f7 to your computer and use it in GitHub Desktop.
Save oliveiraxavier/9cc3bda4ac898f455935917aef0b55f7 to your computer and use it in GitHub Desktop.
//JS
$('.select2').select2({
templateResult: function(e) {
icon = $(e.element).attr('data-icon')
val = e.element;
if(val){
val = `<i class="${icon}"></i> ${val.text}`;
}
return val;
},
escapeMarkup: function(m) {
return m;
}
});
//HTML
<select class="select2">
<option value="1" data-icon="fa fa-users"> TEXTO </option>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment