PDA

View Full Version : Cyclebutton stops working after I add a menu Item?



SlashEMc2k
5 Sep 2011, 7:26 AM
When I add menu Items to cycleButton it seems to break the cycle button and I cannot select the newly added buttons...

I had a look here and tried to insert the extra params but it had no effect?
http://www.sencha.com/forum/showthread.php?138647-text-of-selected-item-on-cyclebutton-isn-t-shown&highlight=cyclebutton

What silly thing have I done to break it?




var vTotalYear = vCurrentYear - 2009;
var vComponentName = ['btnFiscalYearFrom','btnFiscalYearTo'];
for (i=0;i<vComponentName.length;i++){
var vYearsToDisplay = [];
var component = Ext.getCmp(vComponentName[i]);

for (x = 0;x<=vTotalYear;x++) {
var vYear = 2009 + x;
var vYearVal;


if (vYear == vCurrentYear) {
vYearVal = {
id:'active_'+vComponentName,
text:vYear,
xtype:'menuitem',
checked:true
};
} else {
vYearVal = {
text:vYear,
xtype:'menuitem'
};
}
vYearsToDisplay[x]=vYearVal;
}
component.menu.add(vYearsToDisplay);
component.setActiveItem('active_'+vComponentName);
}

SlashEMc2k
6 Sep 2011, 5:22 AM
ok fixed the menu so it's selectable updating -
xtype: 'menucheckitem',



xtype: 'menucheckitem',
checkHandler: component.checkHandler,
group: 'land',
itemIndex: component.itemCount + (x+1),
scope: component


But cycles still not working :-/
But the drop down menu when you select an item is now selected and visible.

Jibbercan
5 Oct 2012, 8:34 AM
Hi there,

You code helped me out. I found two ways to solve this problem.

1. I found that if the cycle button is initially configured with a menu and at least one menucheckitem it wires everything up correctly. Then in my code I use the cloneConfig({text: 'my new item'); to create a new item which becomes a member of the same radio group when I call the menu.add(). Of course I'm removing the initially configured item.



var item = cycle.menu.items.items[0].cloneConfig({text: 'cloned item'});
cycle.menu.add(item);


2. If I follow your example but set the group: 'name of cycle button' then it works too. My guess is that the handler is using the group name to find the Cycle button above it to set the text, etc.



item = Ext.create('Ext.menu.CheckItem', {
text: 'James Sutton',
checkHandler: cycle.checkHandler,
checked: true,
scope: cycle,
group: 'currentUser'
});
cycle.menu.add(item);