1

我在 extjs4 工作。我有激活视图表格- 在此处输入图像描述

对于输入密钥,我将项目视为-

{
                margin:'5 5 5 5',
                xtype: 'fieldcontainer',
                fieldLabel: 'Enter key',
                layout: 'hbox',
                combineErrors: true,
                defaults: {
                    hideLabel: true
                },
                items: [{xtype: 'textfield',    fieldLabel: 'a', name: 'a', width: 80,  allowBlank:false, margins: '0 5 0 0'},
                {xtype: 'textfield',    fieldLabel: 'b', name: 'b', width: 80, allowBlank: false, margins: '0 5 0 0'},
                {xtype: 'textfield',    fieldLabel: 'c', name: 'c', width: 80, allowBlank: false, margins: '0 5 0 0'},
                {xtype: 'textfield',    fieldLabel: 'd', name: 'd', width: 80, allowBlank: false, margins: '0 5 0 0'},
                {xtype: 'textfield',    fieldLabel: 'e', name: 'e', width: 80, allowBlank: false, margins: '0 5 0 0'}]},

我想将每个块中的字符数限制为 5。在第一个块中输入 5 个字符后,我想自动将焦点设置到下一个块。那么如何在 extjs4 中实现这一点

4

1 回答 1

0

您可以添加关键侦听器。您将textfield像这样配置您的东西:

{
    xtype: 'textfield',
    //...other props...
    name: 'a',
    maxLength: 5,
    enableKeyEvents: true,
    enforceMaxLength: true,
    listeners: {
        keyup: function(f, e) {
            if (f.getValue().length == 5)
            {
                var nextField = f.next();
                if (nextField && Ext.isFunction(nextField.focus)) {
                    nextField.focus();
                }
            }
        }
    }
}

如果所有字段都相同,您甚至可以enableKeyEvents, maxLength,enforceMaxLengthlistenersto your 。defaults

于 2013-06-27T12:26:09.670 回答