Results 1 to 4 of 4

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

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    1
      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
      0  

    Default 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();
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •