[英]How to set submit button as default button for form
I have a form in ExtJs 6, I need to set the submit button as the default button to push when enter is pushed in the textfield, here is the code 我在ExtJs 6中有一个表单,我需要将“提交”按钮设置为在文本字段中按Enter键时要按的默认按钮,这是代码
{
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'
}
}]
}
I used references but no success, what can I use or look at as a potential answer 我使用参考但没有成功,我可以使用什么或将其视为潜在的答案
Write one a keypress listeners in text field. 在文本字段中编写一个按键监听器。 and call the handler function of submit button.
并调用“提交”按钮的处理函数。
Below you can find the code. 您可以在下面找到代码。
{
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();
}
}
}]}
Found the answer 找到了答案
I just had to add a specialkey event to the textfield and fire the submit button like this 我只需要在文本字段中添加一个specialkey事件并触发提交按钮,就像这样
if (e.getKey() == e.ENTER) {
var myBtn = Ext.getCmp('macSearch');
myBtn.fireEvent('click', myBtn);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.