Results 1 to 4 of 4

Thread: Reference to function in button handler

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default Reference to function in button handler

    I have a very simple class that is descendant of FormPanel. It maintaines one text field and two buttons. Both buttons has handlers. But one of it inline handler and other like reference to a class function. When i create object of class inline handler fires properly, but by reference just not working. What the problem with code?

    Code:
    Ext.define("Test.TestForm",{
        extend: 'Ext.form.FormPanel',
        id: 'tform',
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 600,
         fieldDefaults: 
        {
          labelAlign: 'top',
          msgTarget: 'side'
        },
        items: 
        [
               { xtype:'textfield', fieldLabel: 'Name', name: 'last_name', style: "margin-left:10px;", anchor: "100%"},
               
          ],
          buttons: 
          [
           { text: 'Test',  scope: this, id: "test_data", handler: function()  {  alert("Test clicked");  } },
           { text: 'Send',  id : "send", handler: this.SendTest }
          ],
        SendTest : function ()  { alert("Sendtest called"); },
        initComponent: function()
        {
            this.callParent();
        }
    });

  2. #2
    Sencha User
    Join Date
    May 2007
    Posts
    20
    Vote Rating
    0
      0  

    Default

    maybe u can set the items on initComponent method

    like
    Code:
        initComponent: function()
        {
        	this.items = 
        	    [
        	           { xtype:'textfield', fieldLabel: 'Name', name: 'last_name', style: "margin-left:10px;", anchor: "100%"},
        	           
        	      ];
        	      this.buttons = 
        	      [
        	       { text: 'Test',  scope: this, id: "test_data", handler: function()  {  alert("Test clicked");  } },
        	       { text: 'Send',  id : "send", handler: this.SendTest }
        	      ];
            this.callParent();
        }

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default

    Thank you. Solution do job well!

    In initComponent "this" exists, but in my case "this" is unexpected DomWindow class if use it outside initialize function.

  4. #4
    Sencha User
    Join Date
    May 2007
    Posts
    20
    Vote Rating
    0
      0  

    Default

    in define method , the scope is window,i think;
    because
    Code:
    window.SendTest = function() {
    	alert('sendtest');
    };
    is ok

Posting Permissions

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