1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    20
    Vote Rating
    1
    mnjacobs is on a distinguished road

      0  

    Default 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();

  2. #2
    Sencha User
    Join Date
    Sep 2008
    Posts
    27
    Vote Rating
    0
    Gunny is on a distinguished road

      0  

    Default


    Hi all,
    I have the same problem, someone has the solution?

    Thanks.

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Location
    Melbourne
    Posts
    11
    Vote Rating
    2
    tetchen9 is on a distinguished road

      0  

    Default


    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)

  4. #4
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    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:

    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();
            }
        }
    
    });
    Ugly, but it works for me.

    Max

Similar Threads

  1. Ext.Button - setPressed() function missing
    By phedoreanu in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 14 May 2013, 12:53 AM
  2. Icons on SegmentedButton Buttons
    By andreig in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 23 May 2011, 3:01 PM
  3. Setting the scroll state of a form to a fixed position on load
    By kevinmike in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 10 Feb 2009, 12:23 PM
  4. setting and retrieving data from state
    By mfw24 in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 15 Nov 2007, 6:12 AM

Thread Participants: 3

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."