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

11,639

Solution 1

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

Solution 2

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.

Solution 3

Blur is the key on Android but disabling the parent is the key on WinJS.

var control = jQuery("#someControl");
// Disabling the parent prevents the keyboard to popup for WinJS.
control.parent().prop('disabled', true);
var options = {
    preset: this.preset,
    mode: 'scroller',
    display: 'bottom',
    timeWheels: "HHii",
    dateFormat: "dd-mm-yy",
    timeFormat: "HH:ii",
    lang: 'nl',
    onBeforeShow: function (inst) {
        // Blur the control because Android will otherwise show the keyboard.
        control.blur();
    }
};
control.mobiscroll(options);
Share:
11,639
Dennis Anderson
Author by

Dennis Anderson

Student Informatica

Updated on June 15, 2022

Comments

  • Dennis Anderson
    Dennis Anderson over 1 year

    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 :)

  • Dennis Anderson
    Dennis Anderson over 9 years
    maybe my pop-up text was a bad idea to say. Because i'm using mobiscroll. This is like a input type that will automatically opens. I have edit my question
  • Dennis Anderson
    Dennis Anderson over 9 years
    Thanx R3tep ! the blur() function helped after all. It was the combination on using mobiscroll with the blur that did the trick !