Danilo
Danilo

Reputation: 2686

ExtJS: focus field

I have a window containing a form (formPanel). Users can show this window clicking on a button in an ExtJS environment. I would like that when the user clicks the button to show the window, a specific field inside the form contained by the window will focus (by this I mean that the cursor should move to that field so that the user can insert data without needing to click on the field itself first).

I tried some solutions, but could not get them work. Any hints?

Here is what I tried, using some examples I found... but it does not work as expected. This function() is called by the ExtJS button in my interface:

function openCardForm(IDUser){

    //Reset the value of this field which may be still there from the prev. usage
    Ext.getCmp('assignFormCARDNUMBER').reset();
    formAssignCard.getForm().load({ 
        url: 'gen/jsonUser.php',
        params:{IDUser:IDUser},
        waitMsg: 'Loading...'
    });
    //Try to focus the Card field when rendering the form
    Ext.getCmp('assignFormCARDNUMBER').on("render",function(){
        Ext.getCmp('assignFormCARDNUMBER').focus(true,10);
    });
    win.show();
}

Upvotes: 3

Views: 10140

Answers (3)

Sam
Sam

Reputation: 21

Or Use

defaultButton : yourComponentToFocusOn

A bit confusing but the defaultButton can be any component (not necessary to be an actual button)

Upvotes: 2

SW4
SW4

Reputation: 71150

You can also try setting the tabindex of the field to zero in its config options...that way you wont even need to add a listener to detect the show event.

ie:

tabIndex:0

Upvotes: 1

einarmagnus
einarmagnus

Reputation: 3592

try on show instead.

Upvotes: 4

Related Questions