Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide soft keyboard and keep input on focus

I have a page for a barcode scanner(honeywell ct50) running Android 4.4.4, The soft keyboard pops up automatically as input textbox is on focus. Is there any solution to hide it? I have read suggestions, mostly making the input losing focus or being readonly, but I need to keep the focus on the input to read the barcode.

I tried 1. to execute event.preventDefault() in onfocus event, it doesn't work. 2. to get the barcode on document.keypress(), the solution in the post as below, but nothing got from my scanner. javascript - hide mobile default keyboard but keep input field active

Any ideas are welcome.

like image 555
Charlene Feng Avatar asked Feb 06 '18 04:02

Charlene Feng


2 Answers

Old topic but this is the solution which works at least for android 6 and 7:

yourInput = document.getElementById('yourInputElement');
yourInput.readOnly = true;
yourInput.focus();
setTimeout(function(){document.getElementById('yourInputElement').readOnly = false;}, 50);

You put your input in readOnly = true before the focus.
The keyboard will not appear.
And you put back the input in readOnly = false but not immediately.
So you can use your scanner without having the keyboard popping up.

like image 90
www.diazis.com Avatar answered Sep 29 '22 02:09

www.diazis.com


For me what worked at some point was setting the ion-input type="text" to readonly, but now it is not working when setting that property. Maybe give it a try.

like image 27
bvprogramit Avatar answered Sep 29 '22 02:09

bvprogramit