Hide mobile keyboard

Hide mobile keyboard

  

When press the "enter"-button on a mobile device I want to trigger an search action and close the keyboard. I get the '$ is not defined' error. My javascript knowledge is letting me down today. Can someone help me?


Hey Martin,

That error means that you're trying to use jQuery without requiring the jQuery lib, so $ is not defined.

You much likely want something like this:


document.addEventListener('keypress', function myFunc(e){
    if(e.which == 13) {
        $actions.MYACTION();
        document.removeEventListener('keypress', myFunc);
    }
});


Let me know if it worked.

Cheers


EDIT: You probably don't want to remove the Listener there, maybe on blur you should remove the listener

Henrique Batista wrote:

Hey Martin,

That error means that you're trying to use jQuery without requiring the jQuery lib, so $ is not defined.

You much likely want something like this:


document.addEventListener('keypress', function myFunc(e){
    if(e.which == 13) {
        $actions.MYACTION();
        document.removeEventListener('keypress', myFunc);
    }
});


Let me know if it worked.

Cheers


EDIT: You probably don't want to remove the Listener there, maybe on blur you should remove the listener

The action does work, but the keyboard won't close. 


Solution

Did you removed the focus from the input? or focus other element?

Something like:

document.getElementById($parameters.MyInput).blur();

Alternatively you can find the Keyboard plugin on the community that allows you to close the keyboard programatically.

Cheers

Solution

Thaks for your help! It works fine now!