2012-04-19 89 views
7

我想调用按钮在文本框中输入功能。ExtJS TextField在点击外部按钮后输入按键

items: [ 
{ 
    xtype: 'form', 
    id: 'myForm', 
    items: [ 
    { 
     xtype: 'textfield', 
     id: 'myTextField', 
     listeners: { 
      specialkey: function(f,e){ 
       if(e.getKey() == e.ENTER){ 
        console.log('Spacial Key = Enter'); // It's working 
        // But i wanna click btnSearch button click event 
      } 
      } 
     } 
    } 
    ], 
    buttons: [ 
     { 
      text: 'Search', 
      id: 'btnSearch', 
      handlers: function(){ 
       // bla bla 
       // bla bla 
       // ... 
      } 
     } 
    ] 
} 
] 

var myform = Ext.getCmp('myForm'); 
myForm.getForm().submit() 

它的工作,但btnSubmit.click功能无法正常工作

回答

1
Ext.getCmp('btnSearch').focus(); 

我不认为它,但其工作对我来说:)

感谢所有

1

这将是更容易地创建像doSearch()的方法,并呼吁从两个处理此方法。

1

根据你的范围,你可以试试这个:

Ext.getCmp("btnSearch").handler.call(Ext.getCmp("btnSearch").scope); 
+0

我尝试过,但我用它等待我搜索并使用form.submit()函数。其点击但不发送表单。但.focus()适用于我。谢谢 – 2012-04-27 15:51:04

1

此代码的工作:

{ 
          fieldLabel : 'Password', 
          name : 'j_password', 
          inputType : 'password', 
          allowBlank : false, 
          listeners : { 
           'render' : function(cmp) { 
            cmp.getEl().on('keypress', function(e) { 
             if (e.getKey() == e.ENTER) { 
              submitform(); 
             } 
            }); 
           } 
          } 
    }