views:

1279

answers:

3

Hi

I'm having trouble adding icons to jQuery UI's buttonset's.Adding icons to buttons work fine.Does anyone have a example of this working

Thanks

Markup

<div id="radio" class='demo'>
    <input type="radio" id="radio1" name="radio" /><label for="radio1">Top 10 FAQ's</label>
    <input type="radio" id="radio2" name="radio" /><label for="radio2">Last 30 Days</label>
</div>

Script

$("#radio").buttonset({ icons: { primary: 'ui-icon-triangle-1-ne'} });
+3  A: 

Update :

Figured it out,pretty simple

$("#radio1").button( { icons: {primary:'ui-icon-gear',secondary:'ui-icon-triangle-1-s'} } );

thanks all

vanzylv
+1  A: 

I struggled with this today as well - a better way, if you're using a buttonset is to apply a class to the elements within and then use the class selector:

$("#choices").buttonset();
$('.graph_checks').button( "option", "icons", {primary:'ui-icon-circle-minus'})
knowncitizen
@knowncitizenHave you noticed that the secondary option does not work on a button set? $("#button-" + uniqueItemId).button( "option", "icons", {primary: 'ui-icon-closethick', secondary: 'ui-icon-closethick'})
vanzylv
I just tried it and it worked fine via the class method that I describe above. Not sure on the method you're using.
knowncitizen
A: 

It turns out that buttonset() re-applies the button decoration classes to the group elements, and all you need is to wrap the grouped buttons in a common element... so you can just initialize your buttons as usual, then apply buttonset() to the desired group afterwards.

This is what I do (example) :

var buttons = {
   '#id1': {group:'group1', options: options1},
   '#id2': {group:'group1', options: options2},
   ....
   '#idn': {group:'group1', options: optionsN}
}
$.each(buttons, function(s,o) { $(s).addClass(o.group).button(o.options); });

$('.group1').wrapAll('<span></span>').parent().buttonset();

Of course, all buttons that needs to be grouped together are already adjacent, but you get the point. This is just an example too!

Yanick Rochon