2016-05-23 136 views
0

我在ExtJS的6形式,我需要設置提交按鈕作爲默認按鈕,按下時,輸入在文本框推,這裏是代碼如何設置提交按鈕作爲默認按鈕形式

{ 
    xtype: 'panel', 
    animCollapse: true, 
    collapseDirection: 'top', 
    collapsible: true, 
    iconCls: 'fa fa-filter', 
    title: 'By Mac Address', 
    items: [{ 
     xtype: 'textfield', 
     id: 'macaddressValue', 
     itemId: 'macaddressValue', 
     padding: 10, 
     fieldLabel: 'Mac Address' 
    }, { 
     xtype: 'button', 
     width: 150, 
     iconCls: 'fa fa-search', 
     text: 'Search', 
     listeners: { 
      click: 'onSearchClick4' 
     } 
    }] 
} 

我曾經引用,但沒有成功,我有什麼可使用或者看起來找到了答案

我剛一specialkey事件添加到文本框一個潛在的答案

回答

0

和消防提交按鈕 像這

if (e.getKey() == e.ENTER) { 
    var myBtn = Ext.getCmp('macSearch'); 
    myBtn.fireEvent('click', myBtn); 
} 
1

在文本字段中寫一個按鍵監聽器。並調用提交按鈕的處理函數。

您可以在下面找到該代碼。

{ 
xtype: 'panel', 
animCollapse: true, 
collapseDirection: 'top', 
collapsible: true, 
iconCls: 'fa fa-filter', 
title: 'By Mac Address', 
items: [{ 
    xtype: 'textfield', 
    id: 'macaddressValue', 
    itemId: 'macaddressValue', 
    padding: 10, 
    fieldLabel: 'Mac Address', 
    listeners: { 
     keypress : function(textfield,eventObject){ 
      if (eventObject.getCharCode() == Ext.EventObject.ENTER) { 
       me.onSearchClick4(); // Call the handler of your Submit button. 
      } 
     } 
    } 
}, { 
    xtype: 'button', 
    width: 150, 
    iconCls: 'fa fa-search', 
    text: 'Search', 
    listeners: { 
     click: { 
      scope : me, 
      fn : me.onSearchClick4(); 
     } 
    } 
}]}