-
21 Oct 2010 12:40 PM #1
Error when setting SegmentedButton state via setPressed (0.97)
Error when setting SegmentedButton state via setPressed (0.97)
I am attempting to set the pressed state of a SegmentedButton, but always get the following error within the setPressed code:
Uncaught TypeError: Cannot call method 'addClass' of undefined
Here is example onReady code to replicate the approach. Is there a problem with how I am doing it?
Code:var panel = new Ext.Panel({ fullscreen: true, items:[ { xtype: 'segmentedbutton', allowMultiple: false, items: [{ text: 'Option 1', pressed: false }, { text: 'Option 2', pressed: false } ], listeners : { toggle : function(container, button, pressed){ console.log("User toggled the '" + button.text + "' button: " + (pressed ? 'on' : 'off')); }, activate: function(segmentedButton){ console.log('activate'); // never called segmentedButton.setPressed(0, true, true); }, afterrender : function(segmentedButton){ console.log('afterrender'); segmentedButton.setPressed(0, true, true); // error } } } ] }); panel.show();
-
21 Mar 2011 11:51 AM #2
Hi all,
I have the same problem, someone has the solution?
Thanks.
-
8 Jul 2011 12:31 AM #3
Up!
In this line in Ext.SegmentedButton in function setPressed
btn.el.addCls(me.pressedCls);
Uncaught TypeError: Cannot call method 'addCls' of undefined
Ext.SegmentedButton.Ext.extend.setPressedsencha-touch-debug.js:21948
(anonymous function)ExpensesItemComponents.js:105
Ext.extend.eachsencha-touch-debug.js:1433
Ext.apply.items.handlerExpensesItemComponents.js:94
Ext.Button.Ext.extend.callHandlersencha-touch-debug.js:21822
(anonymous function)
-
8 Jul 2011 5:00 AM #4
I had the same issue. (Using SenchaTouch 1.1)
The problem arises when you call setPressed and the SegmentedButton is not layed out.
Here is my fix:
Ugly, but it works for me.Code:/** * Ext.SegmentedButton */ Ext.SegmentedButton.override({ addPressedCls: function(btn){ btn.el && btn.el.addCls(this.pressedCls); }, removePressedCls: function(btn){ btn.el && btn.el.removeCls(this.pressedCls); }, /** * Activates a button * @param {Number/String/Button} position/id/button. The button to activate. * @param {Boolean} pressed if defined, sets the pressed state of the button, * otherwise the pressed state is toggled * @param {Boolean} suppressEvents true to suppress toggle events during the action. * If allowMultiple is true, then setPressed will toggle the button state. */ setPressed : function(btn, pressed, suppressEvents) { var me = this; btn = me.getComponent(btn); if (!btn || !btn.isButton || btn.disabled) { return; } if (!Ext.isBoolean(pressed)) { pressed = !btn.pressed; } if (pressed) { if (!me.allowMultiple) { if (me.pressedButton && me.pressedButton !== btn) { me.removePressedCls(me.pressedButton); me.pressedButton.pressed = false; if (suppressEvents !== true) { me.fireEvent('toggle', me, me.pressedButton, false); } } me.pressedButton = btn; } me.addPressedCls(btn); btn.pressed = true; btn.preventCancel = true; if (me.initialized && suppressEvents !== true) { me.fireEvent('toggle', me, btn, true); } } else if (!pressed) { if (!me.allowMultiple && btn === me.pressedButton) { me.pressedButton = null; } if (btn.pressed) { me.removePressedCls(btn); btn.pressed = false; if (suppressEvents !== true) { me.fireEvent('toggle', me, btn, false); } } } if (me.allowMultiple && me.initialized) { me.pressedButtons = me.getPressedButtons(); } } });
Max
Similar Threads
-
Ext.Button - setPressed() function missing
By phedoreanu in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 14 May 2013, 12:53 AM -
Icons on SegmentedButton Buttons
By andreig in forum Sencha Touch 1.x: DiscussionReplies: 1Last Post: 23 May 2011, 3:01 PM -
Setting the scroll state of a form to a fixed position on load
By kevinmike in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 10 Feb 2009, 12:23 PM -
setting and retrieving data from state
By mfw24 in forum Ext 1.x: Help & DiscussionReplies: 2Last Post: 15 Nov 2007, 6:12 AM


Reply With Quote