-
29 Nov 2011 5:59 AM #1
Bug in Button.toggle() when called before rendering
Bug in Button.toggle() when called before rendering
REQUIRED INFORMATION
Ext version tested:- Ext 4.0.7
Irrelevant
DOCTYPE tested against:
Irrelevant
Description:
There is a bug in Button.toggle() code that causes an error when called before the button is rendered.
Steps to reproduce the problem:- Instantiate a button, don't render it
- Call the toggle method
- The button object should change it's state without breaking things
- Error: "Uncaught TypeError: Cannot read property 'dom' of undefined"
No test case, see code below.
HELPFUL INFORMATION
Debugging already done:- There is a line outside the rendered that interacts with the DOM. See code:
Code:toggle: function(state, suppressEvent) { var me = this; state = state === undefined ? !me.pressed : !!state; if (state !== me.pressed) { if (me.rendered) { me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls); } me.btnEl.dom.setAttribute('aria-pressed', state); // <- should go inside the check me.pressed = state; if (!suppressEvent) { me.fireEvent('toggle', me, state); Ext.callback(me.toggleHandler, me.scope || me, [me, state]); } } return me; },
Possible fix:
P.S. The bug is also referred to in this thread but apparently nobody posted a bug report and thus it still hasn't been fixed.Code:/** * Fixes Button.toggle() bug when called before rendering * Found in Ext 4.0.7 */ Ext.override(Ext.button.Button, { toggle: function(state, suppressEvent) { var me = this; state = state === undefined ? !me.pressed : !!state; if (state !== me.pressed) { if (me.rendered) { me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls); me.btnEl.dom.setAttribute('aria-pressed', state); // <- This was outside the check } me.pressed = state; if (!suppressEvent) { me.fireEvent('toggle', me, state); Ext.callback(me.toggleHandler, me.scope || me, [me, state]); } } return me; } });Last edited by Dipish; 29 Nov 2011 at 6:00 AM. Reason: Added reference to another post
-
29 Nov 2011 2:52 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
Thank you for looking into this and providing a possible fix. I can reproduce this error in 4.0.7 but not in our latest code which will be 4.1.0 beta
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote