Omar Faruq
Omar Faruq

Reputation: 1220

Extjs 4.1 How can I call controller method from a form field

I'm using Extjs 4.1.

How can I call a controller method from a form that is already using this method through a button click action? I want this method to be reusable from a form field, but I don't know how to do this.

// here is my controller code

 init: function() {
    this.control({            
        'salewindow button[action=resetAll]': {
            click: this.resertform
        }
    });
},

resertform : function(button){       
    var store = Ext.data.StoreManager.get('Items');
    store.destroy();
    var vatstore = Ext.data.StoreManager.get('Vats');
    vatstore.reload();            
}

//and here is my from field listener

{
    xtype         : 'textfield',
    name          : 'BranchId',
    fieldLabel    : 'Branch Id',
    allowNegative : false,
    id            : 'branchid',
    value         : '1',                
    onBlur        : function(){                                        
        restoreItem();// I want to call above controller method from here
    } 
}

Upvotes: 5

Views: 1761

Answers (1)

Slovo
Slovo

Reputation: 222

Just fire event like:

    {
        xtype         : 'textfield',
        name          : 'BranchId',
        fieldLabel    : 'Branch Id',
        allowNegative : false,
        id            : 'branchid',
        value         : '1',                
        onBlur: function(){                                        
            this.up().down('button[action=resetAll]').fireEvent('click');
        } 
    }

As method up argument, you can use 'window' for example.

Upvotes: 5

Related Questions