I have a Rails app that has a closed back-end. On certain pages, I want to auto-select a text input so I can use an external bluetooth scanner to scan a barcode without selecting it with a mouse/touchscreen every time. This works perfectly on non-mobile devices. However, on mobile devices (mostly tablets), I want the keyboard to popup (as the scanners are viewed as "keyboards" by the system). I know this is prevented by iOS, because it could be annoying. However, I want to know:
Can I have the keyboard auto-appear on Android and/or Windows tablets?
On iOS, can I change this default behavior so the keyboard DOES auto-appear? I have access to all the devices this behavior would be needed.
Edit: I know that I can use a click
event to make the keyboard appear (that is how it appears now). However, I do not want to touch the tablet every time I want to scan.
5 Answers
Answers 1
There are some workarounds except using great prompt()
.
- Wrap the web application into Phonegap and do the following way.
- Keeping in mind that bluetooth scanner needs a first click to enable listening to
keyboard
events, you can slightly change js-code to perform first click manually (say, fullscreentextarea
) and then deal with scanner. It can be atextarea
that hides right after a first click and everything is done withjavascript
without textarea in view. - Looks like Windows smartphones can help you, can't find any issue concerning a problem.
I've tested autofocus fiddle in Chrome56 with Windows 8.1, Windows10 and an old Windows Mobile 8.1 at Nokia Lumia. In first two cases it does listen to keyboard after focusing. The latter one doesn't.
Bonus. HTC One M8 emulator with Android 4.4 listens to keyboard without a click. Tested with browserstack service. What if there are some android examples without need to click?
Bonus2 - autodetect scanner library.
Answers 2
Based on thoses answers you have to try some workarounds
You can't, at least not in iOS (iPhone), and I believe Android as well. It's a usability issue that the keyboard should not be allowed to be triggered except by user input (it's just annoying if it's automatic).
There are a couple of ways I know of to get around this:
prompt()
opens the keyboard- If you trigger the
.focus()
from within a.click()
event (e.g. from >opening your dialog), the keyboard shows up
In your case at the openning of your page ?
Answers 3
You can use JavaScript in built functions for event handling such as focus(), prompt() to initiate bar code scanning function. Also changing some of the usability would also be helpful in this case. For building hybrid apps try some reading on Cordova Keyboard Plugin at https://github.com/cjpearson/cordova-plugin-keyboard
Happy Coding.
Answers 4
try below code. It might work
// div is some selected element var f = function(event) { $timeout(function() { // angular way, setTimeout is OK input[0].focus(); event.preventDefault(); }) }; var mobile = false; div.on('click', function(event) { if(mobile) return; f(event); }); div.on('touchstart', function(event) { mobile = true; f(event); }); div.on('touchend', function(event) { event.preventDefault(); event.stopPropagation(); });
Answers 5
My best bet is using offsite input and focusing there. It will help you to control -
- the timing of keyboard appearance(setTimeOut)
- Check and reopen the keyboard
You will need to do something like this-
<input type="text" style="visibility: hidden; position: fixed; left: -200px" >
With jQuery-
$("#theOffViewBox").focus();
This will work equally on iOS/Android/Windows/Linux as being base JavaScript jugad.
0 comments:
Post a Comment