Search code examples
extjsextjs4extjs-mvc

Extjs 4 set focus on number field


I have a number field in my form named cashPay and another field name is totalPayable. Now if cashPay is less then totalPayable I need to alert a message and focus on the cashPay field. But I am not being able to do it. focus method works on textfield in other form but on number field it is not working for me. Can anyone please help me on this. Here is my code below :

in my view page >>>

{
            xtype: 'numberfield',
            name: 'cashPay',
            id: 'cashPay',
            keyNavEnabled: false,
            mouseWheelEnabled: false,
            enableKeyEvents: true,
            allowBlank: false,
            hideTrigger: true,
            fieldLabel: 'Cash Pay',
            action: 'cashCalculation'
        }

in my controller >>>

Ext.Msg.alert("Warning !","Sorry Cash Pay is less than this month's installment. Please pay the right amount")
        Ext.getCmp('cashPay').focus(false, 1);

Solution

  • The focus method is defined by and inherited from Ext.component. So, if it works for textfield, it should also work for numberfield. It may be something else. You may try to delay a little bit more using

    numberfield.focus(undefined, 20);
    

    Btw: I don't think you should use Ext.getCmp if your numberfield is within a Ext JS form. If you can, use up and down methods to get from your component that is firing the event to your numberfield.