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();
});

2 Answers 2

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();
  ...
});
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.