I would like to place an icon in the selected item of a SelectMenu item.
Like this way. I have managed to add the icons in the drop-down, but I can not put it there.
The code I used is this:
<div class="select-lang">
<?
$check = $sql->query("SELECT * FROM '".PREFIX."langs' WHERE 'active' = '1' ORDER BY 'int_name' ASC");
echo "<select class='languages'>";
while($show = $check->fetch_object()){
echo "<option value='".$show->lang."' data-class='".$show->lang."' data-title='".$show->int_name."'>".$show->name."</option>";
}
echo "</select>";
?>
</div>
At first I generate the whole structure with what I have stored in the database. Now with Jquery UI the following:
<script type="text/javascript">
$(document).ready(function(){
$.widget( "custom.iconselectmenu", $.ui.selectmenu, {
_renderItem: function( ul, item ) {
var li = $( "<li>", { text: item.label, "title": item.element.attr( "data-title" ) } );
if ( item.disabled ) {
li.addClass( "ui-state-disabled" );
}
$( "<span>", {
style: item.element.attr( "data-style" ),
"class": "ui-icon " + item.element.attr( "data-class" )
})
.appendTo( li );
return li.appendTo( ul );
}
});
$('.languages')
.iconselectmenu()
.iconselectmenu('menuWidget')
.addClass('ui-menu-icons customicons');
});
</script>
Well, this is the doubt. Greetings.