1

I have been searching for how to trigger the android keyboard via Javascript.

I have found a few answers but none of them seem to work.

One solution is here: Showing Android's soft keyboard when a field is .focus()'d using javascript

On the example above there is a button involved which I don't have, but do I need it?

I am using 'tap' and 'swipe' events via the touch-layer.js which seems to disable click events in favour of tap. (https://github.com/cubiq/touch-layer)

Below is the code I've tried, the alert triggers and the focus happens but the keyboard doesn't show.

gt("#txtEmail").on("tap", function() {
    alert('tap');
    $(this)[0].el[0].focus();
    $("#txtEmail").trigger('click');
});

Thanks.

EDIT 1: Second attempt doesn't work even though this seems more inline with the example.

gt("#txtEmail").on("tap", function() {
    alert('trigger');
    $("#txtEmail").trigger('click');
});

$("#txtEmail").on("click", function() {
    alert('recieved');
    $(this).focus();
});
Community
  • 1
  • 1
SkelDave
  • 1,176
  • 2
  • 9
  • 23

2 Answers2

3

In addition to Jack He's suggstion, check out ionic-plugin-keyboard. This one is more actively maintained and used by many.

In my case, I just bound focus event to a handler function that manually shows the keyboard.

$(".my-input").on("focus", function(e) {
  ...
  cordova.plugins.Keyboard.show();
  ...
});
mc9
  • 6,121
  • 13
  • 49
  • 87
1

What you need is the SoftKeyBoard plugin. Just check the link to find what you want.

Jack He
  • 1,683
  • 3
  • 18
  • 29