An example with Awesome icons font (can be easily formated to <img>
tag instead of <i>
)
var icons = [];
$.each({
"compass" : "icon-compass",
"eur" : "icon-eur",
"dollar" : "icon-dollar",
"yen" : "icon-yen",
"won" : "icon-won",
"file-text" : "icon-file-text",
"sort-by-attributes-alt" : "icon-sort-by-attributes-alt",
}, function (k, v) {
icons.push({
id: k,
style: v
});
});
function format(icon) {
if (!icon.id) return icon.style;
return "<i class='icon-" + icon.id + "'></i> " + icon.style;
}
$('#awsome_icons_select').editable({
inputclass: 'form-control input-medium select2',
select2: {
allowClear: true,
formatResult: format,
formatSelection: format,
escapeMarkup: function (m) {
return m;
}
},
source: icons,
display: function (value) {
if (!value) {
$(this).empty();
return;
}
var html = "<i class='icon-" + value + "'></i> ";
$(this).html(html);
}
});
This should do the trick for image:
var countries= [];
$.each({
"US" : "USA",
"RU" : "Russia",
"DK" : "Denmark",
"FR" : "France",
"PL" : "Poland",
"DE" : "Germany",
"GB" : "Great Britain",
}, function (k, v) {
countries.push({
id: k,
state: v
});
});
function format(country) {
if (!country.id) return country.state;
return "<img src='path_to_images/" + country.id + ".png' /> " + country.state;
}
$('#countries_select').editable({
inputclass: 'form-control input-medium select2',
select2: {
allowClear: true,
formatResult: format,
formatSelection: format,
escapeMarkup: function (m) {
return m;
}
},
source: countries,
display: function (value) {
if (!value) {
$(this).empty();
return;
}
var html = "<img src='path_to_images/" + value + ".png' /> ";
$(this).html(html);
}
});