Open mobile keyboard automatically

Currently I have the following block attached to the user action.

$(".class-botao").focus()

When the user interacts with the page the mobile keyboard is displayed normally.

But in my application there is a method that checks if there is any empty input when loading the page and if there is I give a .focus() in the element;

autoFocus: function(scope) {
    var firstInput = $('.class-input.empty:required').filter(':first:visible');

    if (!firstInput.length) {
        return false;
    }

    firstInput.focus();
    return true;
},

Everything works normally but the keyboard does not appear (IOS/Android),

I tried to simulate events .trigger('click // touchstart') soon after from focus(), but nothing from the keyboard appears : /

Anyone have any tips ?

Author: Douglas Neves, 2016-09-13

1 answers

The mobile virtual keyboard can only be activated by user actions , by usability settings.

In this way, the correct method to invoke the keyboard of mobile devices is through the type of the input element, for example:

<input type="text" /> will automatically invoke the default alphanumeric keyboard when receiving focus, while
<input type="number" /> will invoke the numeric keypad

There are two exceptions for javascript:

  • Some say that the global method prompt() works
  • Trigger Event focus within events raised by user action, for example: click, mousedown, or mouseup
 2
Author: rabelloo, 2016-11-15 23:11:41