how to hide keyboard in jquery mobile programmatically on focus()
Asked Answered
P

4

8

I want to hide the keyboard on Focus(),but when $(".ui-input-text").focus(); it will automatically open the keyboard .

I just want to hide in particular screen ,I have test with document.activeElement.blur(); but it also did not focus() on input .

Pyrogallol answered 14/12, 2013 at 4:56 Comment(2)
This seems perverse. You want to focus a user input field, but disable the input method? Why?Bobo
i have my custom keyboard on screenPyrogallol
B
14

When submitting a form, at times, the iOS Keyboard may not automatically close. This is quite a usability issue as Users should not be required to manually close the Keyboard for use-cases in which they would otherwise not expect the need do so.

A simple solution for this can be implemented by invoking the blur method on document.activeElement, which effectively allows one to programmatically hide the keyboard:

// automatically close the keyboard on iOS
document.activeElement.blur();

More about HTML5 and Mobile application events ..

http://www.ericfeminella.com/blog/2012/12/27/ios-html5-input-element-tips/

Bort answered 14/12, 2013 at 10:47 Comment(0)
B
1

Try this:

$('#yourElement').blur();

It will hide the virtual keyboard.

Bott answered 14/12, 2013 at 5:20 Comment(1)
i have used this one but when i use it also not focus () on inputPyrogallol
T
1

From here

var hideKeyboard = function() {
    document.activeElement.blur();
    $("input").blur();
};

Edited : another option

$('.clr').after('
        //<input tyep="checkbox" 
        <input type="checkbox"
               id="focusable" 
               style="height:0;
               margin- left:-200px;
               clear:both;" />');
$('#focusable').focus(); `
Techno answered 14/12, 2013 at 5:40 Comment(2)
but issue was that when i add this code it also loose the focus from the inputPyrogallol
@Gamex you can assing focus again as shown in another option.Techno
C
1

Is this oversimplifying? :

<input id="x" inputmode="none" value="x">

I tangled with scripts for hours, and found this was a simpler and more reliable way to hide the keyboard when the input was being used for other stuff.

Cramer answered 30/5, 2024 at 2:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.