Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide virtual keyboard on mobile with Jquery/Javascript (Mobiscroll)

There are a lot of questions about this. But they all talk about leaving the focus on a field. Here is my problem:

I have a input type field. When the user clicks on it, it will open my custom mobiscroll feature. and in some cases like by Android 2.* or windows surface tablets it shows the virtual keyboard as well ! How can i code a case that the virtual keyboard will never appear !

Who can help me :)

like image 323
Dennis Anderson Avatar asked Aug 04 '26 23:08

Dennis Anderson


2 Answers

To remove the keyboard you need to lose the focus on the active element. No other solution.

So display your pop-up and after remove the focus.

Example:

function clickInput() {
    openPopUp();
    document.activeElement.blur(); // lose focus on the active element and hide keyboard
}

UPDATE:

I do not know "mobiscroll". But to hide the keyboard you need to lose focus on the active element.

document.activeElement && document.activeElement.blur();
// This code remove the keyboard constantly.
like image 85
R3tep Avatar answered Aug 06 '26 14:08

R3tep


Blur was the key for my issue ! Mobiscroll has a method called onBeforeShow that gets called before the mobiscroll appears. In this method I used blur() on the input type i used the mobiscroll on ! My code below:

var options = {
        preset: this.preset,
        theme: 'wp light',
        mode: 'scroller',
        display: 'bottom',
        timeWheels: "HHii",
        dateFormat: "dd-mm-yy",
        timeFormat: "HH:ii",
        lang: 'nl', // TODO: Deduce from application language.
        onBeforeShow: (html, inst) => { this.findControl().blur();}
    };
    this.findControl().mobiscroll(options);
like image 43
Dennis Anderson Avatar answered Aug 06 '26 13:08

Dennis Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!