Set focus on Extjs textfield

后端 未结 11 1670
星月不相逢
星月不相逢 2020-12-31 02:02

Currently I got problem with setting focus on extjs textfield. When form show, I want to set focus to First name text box and I try to use build in function focus() but stil

相关标签:
11条回答
  • 2020-12-31 02:21
    UIManager.SetFocusTo = function (row, column) {
        var grd = Ext.getCmp('gridgrn');
        grd.editingPlugin.startEditByPosition({ 'column': column, 'row': row });
    
    }
    
    0 讨论(0)
  • 2020-12-31 02:22

    why not just add defaultFocus : '#first_name' instead of adding to much lines of code?

    OR, after this.callParent(arguments); add this line Ext.getCmp('comp_id').focus('', 10);

    0 讨论(0)
  • 2020-12-31 02:22

    I've been struggling with that issue today, and I think I got the solution. The trick is using the focus() method after the show() method was called on the Form Panel. That is, adding a listener to the show event:

    Ext.define('My.form.panel', {
        extend: 'Ext.form.Panel',
        initComponent: function() {
            this.on({
                show: function(formPanel, options) {
                    formPanel.down('selector-to-component').focus(true, 10);
                }
        });
        }
    });
    
    0 讨论(0)
  • 2020-12-31 02:29

    Sometimes it helps to add a little delay when focusing. This is because certain browsers (Firefox 3.6 for sure) need a bit of extra time to render form elements.

    Note that ExtJS's focus() method accepts defer as an argument, so try that:

    Ext.getCmp('first_name').focus(false, 200);
    
    0 讨论(0)
  • 2020-12-31 02:30

    Based on Pumbaa80's answer and Tanel's answer I have tried many things and found a way to do it. Here is the code:

    {
        fieldLabel: 'First Name',
        name: 'first',
        id: 'first_name',
        allowBlank: false,
        listeners: {
          afterrender: function(field) {
            field.focus(false, 1000);
          }
        }
    }
    
    0 讨论(0)
提交回复
热议问题