5

I've been working for days to work around the limitation of iOS that doesn't allow auto focus on text field on Ipad. The issue is well explained here Mobile Safari Autofocus text field.

My goal is to be able to scan a bar code via a Bluetooth Scanner directly on screen without the user interaction.

I managed to set the AutoFocus by simply doing, I've tested it on iOS v6

      $('#MyTextField').trigger('focus');

document.activeElement is returning my text field by there is no CURSOR on the text field. Is is normal?

I think because the the cursor is not displayed on the text box, the keyboard is not displayed, and because the keyboard is not displayed, the keypress event is not firing when I use the scanner!

Community
  • 1
  • 1
  • Did you get to a solution? I have a similar one and im able to get the focus correct, but cursor doesn't appear and hence keyboard is not triggered too. – Roy M J Sep 26 '15 at 18:16

1 Answers1

0

As the discussion in the SO you link to in your question covers, the input cannot be focussed programmatically. It seems widely accepted that this is expressly to prevent programmatic display of the keyboard, for UX (and possibly security) reasons. That activeElement is set to the input sounds like an oversight in the code that prevents the focus from being set, rather than an indication that it can be worked around.

You can probably confirm that the field is not actually focused by adding some css:

input::focus {
    border: 1px solid red;
}

(there are of course default focus styles for inputs; I mention this simply to make it absolutely clear)

Tom Jardine-McNamara
  • 2,418
  • 13
  • 24