Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    100
    Vote Rating
    0
    Dipish is an unknown quantity at this point

      0  

    Default 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
    Browser versions tested against:
    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 result that was expected:
    • The button object should change it's state without breaking things
    The result that occurs instead:
    • Error: "Uncaught TypeError: Cannot read property 'dom' of undefined"
    Test Case:

    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:
    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;
        }
    });
    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.
    Last edited by Dipish; 29 Nov 2011 at 6:00 AM. Reason: Added reference to another post

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread