tags:

views:

285

answers:

2

Hi,

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();
}
+3  A: 

try on show instead.

ormuriauga
Thanks, that worked. Actually I finally put the new handler on the show event of the window where the form is inserted. Moreover, I added some delay for focusing the element, which seems to be necessary. The focusing code became: Ext.getCmp('assignFormCARDNUMBER').focus(true,800);
Danilo
+1  A: 

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
Ergo Summary
really?! that is awesome. thank you for sharing +1
ormuriauga