Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile Show Keyboard on Input Focus

I am having a problem getting the Android keyboard to show up when I focus a text input. I have this in my function that initializes the page:

jQuery(document).bind('pageshow', function()
{
    jQuery($inputItemReference).focus();
    jQuery($inputItemReference).prompt();
});

$inputItemReference is a variable that points to the input text box.

I was told that prompt() would show the keyboard. However, it does not. I am only getting the input to display the blinking cursor when the page loads. If I want the keyboard to be displayed, I have to tap the input again. I want the keyboard to be displayed right when the page loads. Any thoughts? Thanks.

like image 881
snowfi6916 Avatar asked Jan 16 '13 15:01

snowfi6916


2 Answers

If you are using cordova/phonegap add this to config.xml:

<preference name="KeyboardDisplayRequiresUserAction" value="false" />
like image 81
des1001 Avatar answered Sep 20 '22 20:09

des1001


Based on this answer, Show virtual keyboard on mobile phones in javascript, it is not readily possible.

You can't, at least not in iOS (iPhone), and I believe Android as well. It's a usability issue that the keyboard should not be allowed to be triggered except by user input (it's just annoying if it's automatic).

There are a couple of ways I know of to get around this:

prompt() opens the keyboard If you trigger the .focus() from within a .click() event (e.g. from opening your dialog), the keyboard shows up

like image 30
Twisty Avatar answered Sep 17 '22 20:09

Twisty