【问题标题】:How to set submit button as default button for form如何将提交按钮设置为表单的默认按钮
【发布时间】:2016-05-23 07:49:06
【问题描述】:

我在 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'
        }
    }]
}

我使用了参考但没有成功,我可以使用或查看什么作为潜在答案

【问题讨论】:

    标签: javascript extjs


    【解决方案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();
            }
        }
    }]}
    

    【讨论】:

      【解决方案2】:

      找到答案

      我只需要在文本字段中添加一个特殊键事件并触发提交按钮 像这样

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

      【讨论】:

        猜你喜欢
        • 2011-01-05
        • 2012-01-22
        • 1970-01-01
        • 1970-01-01
        • 2013-09-29
        • 1970-01-01
        • 2010-12-30
        • 1970-01-01
        • 2012-11-18
        相关资源
        最近更新 更多