Results 1 to 4 of 4

Thread: Button handler doesn't work if added inside a button variable

  1. #1
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
      0  

    Default Answered: Button handler doesn't work if added inside a button variable

    Hey,

    I have a problem adding a simple handler function to a button, if the button is stored in a variable...
    Here's a simple test case created with senchafiddle:
    Code:
    var han = function(btn, evt)
        {
            alert("Button tapped.");
        };
    
    var button1 = Ext.create('Ext.Button',
                             {
                                 text: 'button1',
                                 handler: han
                             });
    
    Ext.application({
        name: 'SenchaFiddle',
        launch: function() {
            Ext.create('Ext.Panel', {
                fullscreen: true,
                items: [
                    {
                        xtype  : 'toolbar',
                        height: '100%',
                        docked : 'top',
                        defaults: {width: 100, margin: 5},
                        items: [button1, {xtype: 'button', text: 'button2',  handler: han}]
                    }
                ]
            });
        }
    });
    The result is that the handler of button1 doesn't work, the handler of button2 works fine. What I'm doing wrong?
    Both handlers work fine for me with ST1.x, but not with ST2...
    Thx for your help!

  2. You should not instantiate a component outside Ext.setup or Ext.application like that. If you do the Ext.create within the launch method, everything will work.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,897
    Answers
    3970
    Vote Rating
    1329
      0  

    Default

    You should not instantiate a component outside Ext.setup or Ext.application like that. If you do the Ext.create within the launch method, everything will work.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
      0  

    Default

    Thanks Mitchell, I appreciate your help...

  5. #4
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
      0  

    Default

    Ok, I'm running into simular problems, because my app has many JS files where all components are created outside the launch function in variables, like this:
    Code:
    var aName = Ext.create('Ext.Panel',{...)
    The result is, that the panels are displayed, but buttons or togglefields don't work anymore.

    I don't want to put all my components into the launch function and have one big file... Another solution is to create classes instead of my "global varibles":
    Code:
    Ext.define('AName',{
    extend: 'Ext.Panel', config: { - orginal Panel config - }
    });
    Then I have just to add one line into my launch function, for example:
    Code:
    var aName = Ext.create('AName', {});
    Is this a good idea or are there better ways?
    Thx again for your help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •