• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[SOLVED]Sencha touch autofocus on textfield

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED]Sencha touch autofocus on textfield

    I am having an awful time trying to progmatically focus a field with sencha touch. When the view is first pushed to the screen it works. i am using a reference to get to the field and then calling .focus(). That works. This is an inventory app so the user will be entering many scans...so after each scan it needs to set the focus back to the field...ready for the next scan. It will not work! Has anyone else come across this issue? Thanks for any assistance.

    Ryan

  • #2
    Can you post the part of your code which is setting the focus on the field after a scan?

    Comment


    • #3
      this is called on the action event for the textfield.

      Code:
      onActionFabricScan: function() {
              var fabrics = Ext.getStore('FabricsSql');
      
              var scan = this.getFabricScan().getValue();     // get barcode value.
      
              if (fabrics.findExact("SCANID", scan) > 0) {
                  console.log('good fabric');
              }
      
              this.getFabricScan().setValue('');
              this.getFabricScan().focus();
              
          }

      Comment


      • #4
        Are you sure this code is being run? Is the form in focus? Are any other events being fired off around the same time?

        Comment


        • #5
          I am sure the code is being run. No other events are fired off. Now form is focus not sure. the form is visible on the screen.
          I type a barcode# in the field and hit enter...the code runs....i've done some console logs to verify....the cursor never gets put back in the field. This is driving me bananas! Thanks for your replies.

          Comment


          • #6
            Are you running this through the Valence Portal or is this application wrapped in Phonegap? If its wrapped with Phonegap you need to change your config file KeyboardDisplayRequiresUserAction to false since it defaults to true.

            <preference name="KeyboardDisplayRequiresUserAction" value="false" />

            Comment


            • #7
              I have wrapped this with phonegap. changing the preference did not work. :-(. I must have something really messed up. After more playing around with it I have found out if I add the line (no sencha code just old fashioned javascript)
              Code:
              document.forms[0].fabricscan.focus()
              It will not work. The code is correct but my cursor does not focus on the text field. now if I say this
              Code:
              document.forms[0].fabricscaxxx.focus()
              This is obviously wrong. (misspelled fieldname) I get an error which i should....but it works!! the cursor is put right in the field ready to go.

              so then i thought well maybe i don't need to worry about coding the focus function...so i took out the focus code and it does not work....so i have no clue how a broken line of code can set the field.

              Comment


              • #8
                Keep that change in your config because you definitely need that. Now what version of Sencha Touch are you using? Sencha fixed the focus bug in 2.3.

                Thanks

                Comment


                • #9
                  Johnny, sorry for the delay. This issue has been driving me nuts. I am using 2.3 and wrapping with phonegap 3.
                  I cannot even get this to work on a desktop version of safari or chrome. (well it will work if i monitor for the keyup event and then insert the bad line of code mentioned above. But since I am using a barcode scaner the keyup event does not work in iOS7. Is it a bug in 2.3 focus() method. I know it can be done because i am using a jquery app i wrote that does the same thing. They use the jquery in mobile safari and it allows me to set the focus. I am trying to convert this to sencha though. Any guidance is appreciated.

                  Comment


                  • #10
                    Quick update....after literally wasting about 10 hours on this specific issue I seem to have figured out a work around. I had to ditch the textfield class in sencha and just use a straight html text box in side an touch component using the html property. I then manually added a keypress function to the textfield in the controller
                    Code:
                    Ext.get('field').dom.keypress = function(e) {}
                    and monitored for the CR (13). did my processing and cleared the field and set the focus back to the field and it worked! Not very elegant but it works.
                    For some reason iOS 7 when using a bluetooth scanner does not like the keyup event provided by sencha. It always sends back the keycode = 0. I ended up having the use the keypress event and using the charCode to get the right character.

                    Comment


                    • #11
                      Thanks for posting your final solution. This may help others trying to do the same thing.

                      Comment

                      Working...
                      X