Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autofocus text field on mobile, but no keyboard?

As part of my login and registration forms, if there are errors then it will autofocus the related field. Actually, it not as simple as I thought. Let me try to explain!

Basically, on this project, pages are loaded with AJAX. Forms may include an autofocus attribute. This works great, but on mobile it just shows the cursor without bringing up the keyboard, meaning you still have to tap the input to start typing.

Am I missing something, or do I have to double-up the focussing with something like

document.querySelector("[autofocus]").focus();
// with appropriate verification that the element exists, of coursr
like image 297
Niet the Dark Absol Avatar asked May 18 '14 14:05

Niet the Dark Absol


1 Answers

In mobile devices (at least in Apple's Safari), the keyboard isn't allowed to show up without the user clicking on the input field. It's by design, and I don't think there is much you can do about it.

http://www.quora.com/Mobile-Safari-iPhone-or-iPad-with-Javascript-how-can-I-launch-the-on-screen-keyboard

like image 137
Tarun Avatar answered Oct 13 '22 22:10

Tarun