I'm looking to create a dropdown for colors that has each color as a small square next to the item.
Have:
Want (roughly):
This version (jsfiddle) works fine for the dropdown items themselves, but I'd like the button to also update to have the colored square next to it.
$.widget("custom.coloriconselectmenu", $.ui.selectmenu, {
_renderItem: function (ul, item) {
var li = $("<li>", {text: item.label});
var bgColorStyle = 'background-color:' + item.element.attr("data-color");
var fullStyle = "float: left; width: 21px; height: 19px; margin-right: 7px;" + bgColorStyle;
$("<div>", {style: fullStyle}).appendTo(li);
return li.appendTo(ul);
}
});
$("#selectId").coloriconselectmenu({icons: {button: "custom-button"}});
Is there a good way to modify the dropdown button on value update to include the color square like in the dropdown?