微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – ExtJs在ENTER按键上模拟TAB

我知道这不是最明智的想法,但我仍然必须这样做.
我们的用户希望像TAB一样使用ENTER.
所以,我想出的最好的是:

Ext.override(Ext.form.field.Base, {
            initComponent: function() {
                this.callParent(arguments);

                this.on('afterrender', function() {
                    var me=this;
                    this.getEl().on('keypress',function (e){
                        if(e.getKey() == 13) {
                            me.nextNode().focus();
                        }
                    });
                });
            }
        });

但它仍然与TAB完全不同.
我的意思是,它适用于输入字段,但不适用于其他控件.
可能有一些低级别的解决方案.
有任何想法吗?

解决方法:

在过去,我已将监听器附加到文档中,如下所示:

Ext.getDoc().on('keypress', function(event, target) {

    // get the form field component
    var targetEl = Ext.get(target.id),
        fieldEl = targetEl.up('[class*=x-field]') || {},
        field = Ext.getCmp(fieldEl.id);

    if (
        // the ENTER key was pressed...
        event.ENTER == event.getKey() &&

        // from a form field...
        field &&

        // which has valid data.
        field.isValid()

        ) {

        // get the next form field
        var next = field.next('[isFormField]');

        // focus the next field if it exists
        if (next) {
            event.stopEvent();
            next.focus();
        }                   
    }
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐