Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Allow Autoshow Keyboard on Mobile

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:

  1. Can I have the keyboard auto-appear on Android and/or Windows tablets?

  2. 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.

like image 422
Ryan K Avatar asked Jan 17 '17 21:01

Ryan K


4 Answers

There are some workarounds except using great prompt().

  1. Wrap the web application into Phonegap and do the following way.
  2. 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, fullscreen textarea) and then deal with scanner. It can be a textarea that hides right after a first click and everything is done with javascript without textarea in view.
  3. 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.

like image 77
shukshin.ivan Avatar answered Nov 11 '22 13:11

shukshin.ivan


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 ?

At least maybe this JS fiddle can help you or this one

like image 30
Seba99 Avatar answered Nov 11 '22 14:11

Seba99


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.

like image 3
Atul Jindal Avatar answered Nov 11 '22 13:11

Atul Jindal


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();
            });
like image 1
Swanand Avatar answered Nov 11 '22 14:11

Swanand