-
14 Sep 2012 8:03 AM #1
Unanswered: Toggle Button Group - all buttons can be unpressed
Unanswered: Toggle Button Group - all buttons can be unpressed
I'd like to replicate a radio button group behavior - at least 1 button is selected, but it seems that all buttons in the toggle group can be unpressed.
any work around?
-
14 Sep 2012 10:26 AM #2Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
See if this works for you:
Scott.Code:Ext.create('Ext.menu.Menu', { width: 100, margin: '0 0 10 0', floating: false, // usually you want this set to True (default) renderTo: Ext.getBody(), // usually rendered by it's containing component items: [{ text: 'regular item 1', group: 'mygroup', checked: true },{ text: 'regular item 2', group: 'mygroup', checked: false },{ text: 'regular item 3', group: 'mygroup', checked: false }] });
-
14 Sep 2012 5:47 PM #3
-
14 Sep 2012 6:58 PM #4
FYI: This solution does not check initial state of buttons yet.
Code:Ext.onReady(function(){ Ext.define('GroupButton', { extend: 'Ext.button.Button', alias: 'widget.groupbutton', toggleGroup: 'defaultGroup', initComponent: function(){ var me = this; me.callParent(arguments); }, toggleHandler: function(button, state){ var me = this; if(!(me.pressed || Ext.ButtonToggleManager.getPressed(me.toggleGroup))){ me.toggle(true, true); } } }); Ext.create('Ext.panel.Panel', { renderTo: Ext.getBody(), width: 400, height: 300, tbar: { items: [{ xtype: 'groupbutton', text: 'Button 1', pressed: true },{ xtype: 'groupbutton', text: 'Button 2' },{ xtype: 'groupbutton', text: 'Button 3' }] } }); });
-
15 Sep 2012 5:47 AM #5Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
Err, I misunderstood the requirement. Vietits should work fine.
Sorry for the misunderstanding.
Scott
-
7 Nov 2012 5:03 PM #6
I just tried Vietits' solution and it worked great. No need to recreate a button group though, I was able to do it directly....
var newButton = Ext.widget('button', {
...
toggleHandler : function(button, state){ //prevent all unpressed. Sencha workaround.
var me = this;
if(!(me.pressed || Ext.ButtonToggleManager.getPressed(me.toggleGroup))){
me.toggle(true, true);
}
}
});
Of course the best solution would be for the Button object to have a parameter that prohibits toggle groups from having all buttons toggled.
-
7 Nov 2012 5:12 PM #7Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 171
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
8 Nov 2012 10:30 AM #8
Ah. You're right. I've updated my solution to use that config option now.


Reply With Quote