1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    1
    chris_np is on a distinguished road

      0  

    Default Unanswered: How to set focus on a field after it displays?

    Unanswered: How to set focus on a field after it displays?


    I've got a view which animates in from the right with an slide animation.

    On that view I have a number field which I want to have focus, so the keyboard is up and ready to be typed on.

    But I can't seem to pass the focus to the field. Any thoughts?

    In the config of the view I have this code (along with other lines I've missed out):

    Code:
    items: [
       {
          xtype: "numberfield",
          id: "numPaymentAmount"
       }
    ]
    
    listeners: {
       painted: function() {
          Ext.getCmp("numPaymentAmount").focus();
       }
    }

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,206
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Mobile devices have always had an issue with forcing focus or even blur. Executing focus is the best bet but may nto work. You can try delaying the firing of it to see if some time after the painted event has fired if it can focus.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    1
    chris_np is on a distinguished road

      0  

    Default


    Hmmm. I tried setting the focus on button click, so the view was already rendered and everything, but that worked on my PC but not on the mobile device.

    If that doesn't work, it seems I can't set focus on the field at all - not after delay or on button click or on painted.

    Oh well.

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    2
    Vote Rating
    1
    sutong324 is on a distinguished road

      0  

    Default I have fixed this bug

    I have fixed this bug


    After review Button.js 's code I know how to fix this bug which many people faced the same problem and I do not want to has it alone.


    You can add below code in your own tap event method before show another page:

    if (e && e.preventDefault) {
    e.preventDefault();
    }

Thread Participants: 2

Tags for this Thread