Hide keyboard

Posted by marius.nistor07 on 13-Oct-2014 03:12

Hi,

I have a hidden input field that always must have focus. If the user touches the screen, that field shouldn't lose the focus. For some reason Tap event on the page has no efect and it doesn't run my javascript. So on Blur event, for that input field, I'm setting back the focus but the keyboard appears. Is there a way to hide the keyboard or what event should I choose to set focus for that input field?

Thanks in advance

All Replies

Posted by Bill Wood on 14-Oct-2014 07:02

Can you give more examples?   If the field is hidden, then the concept of 'focus' on the field is hard to understand --- what are you trying to accomplish (and for the record, what is the platform/OS -- is this a Cordova (Hybrid) application, or are you using the native browser?  and what platform?

Posted by ymaisonn on 14-Oct-2014 07:46

You can't trigger the focus event on hidden field. It will even trigger an error with IE, according to jQuery doc.

"Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use .focus() on elements that are visible. To run an element's focus event handlers without setting focus to the element, use .triggerHandler( "focus" ) instead of .focus()."

http://api.jquery.com/focus/

Alternatively, you may set the field in a div  and set it to transparent (opacity:0)

HTH

Posted by mihai_neagoe on 14-Oct-2014 07:56

Hi Bill,

This is a mobile application for a scanning device. On the scan action a request is made to get data from Business Logic. In order to make the request we use a 'dummy' field which is populated from scan. We want to hide the field because it has no relevance for the user but keep the focus on this field at all time - this is to let the user to keep scanning without other button press and also we want to prevent the situation when the user touches the screen (in this situation we want to catch the tap event and set the focus back in the field).

Note that the field does not have the hidden property set - only the opacity is set to 0 so the user wil not see it.

Posted by Bill Wood on 14-Oct-2014 08:06

Is this on all platforms (android and iOS)? What is the browser? (Or are you on Cordova / hydrid?)=

Posted by egarcia on 14-Oct-2014 08:15

Hello,

What about populating a localStorage variable instead of a field?

Thanks.

Posted by Roger Blanchard on 14-Oct-2014 08:17

We do as Edsel says. We populate a localStorage variable and then execute the service.

Posted by mihai_neagoe on 14-Oct-2014 08:36

The application is deployed for android (we generate the apk file and install it on the scanner device).

Is it possible to direct the output of the scanner to a localStorage variable? The scan output goes into this 'dummy' field on each request - if the focus is not on it then the output of the scan is lost. In this case loosing the focus on the field prevents further scans.  

Posted by Roger Blanchard on 14-Oct-2014 09:08

I guess it depends on the scanner. Today, I am using the camera to scan barcodes (slower then an actual scanner) and an event fires when it reads a barcode. In this event I can do whatever I need such as write the scanned data to localStorage and then execute a service.

How are you handling populating this 'dummy' field now?

Posted by egarcia on 14-Oct-2014 09:37

The barcode scanner service (Device service) can be mapped to UI components or to localStorage variables.

It looks like the scanner that you are using simulates user input as a keyboard. Could you confirm if that is the case?

How does it signal end of input? Does it use a return?

Perhaps, a solution could be to use a different component, for example, a button and detect the keystrokes (keypress, keyup, keydown events).

I hope this helps.

Posted by egarcia on 14-Oct-2014 09:46

Depending on the scanner, there may also be a JavaScript interface via PhoneGap.

Posted by Anil Kumar on 14-Oct-2014 10:57

Hi,

I tried creating a sample mobile app which uses Barcode device service that is shipped with Mobile App Builder (appdesigner.rollbase.com) and am able to store the data in local storage (and alert) variable and UI label.

We can use the same local storage variable for computation purpose by mapping to respective data elements (of OpenEdge backend) and perform the necessary operations.

Hope this helps.

Thanks and Regards,

Anil Kumar.

Posted by mihai_neagoe on 15-Oct-2014 06:24

We use the output of the scanner to fill in the input (as Edsel mentioned) - as I can see the output cannot be mapped to a localStorarge variable. The problem we have with the BarcodeService is that no event is triggered by the scan action.

There is no signal for the end of the input - we invoke our service when the barcode length (13) is reached (the input event is triggered for each digit in the barcode).

On invoke success the focus is set back on the input and keyboard blured.

Posted by Bill Wood on 15-Oct-2014 07:22

WRT this:

 >> The application is deployed for android (we generate the apk file and install it on the scanner device).

It sounds like this is not a 'normal' mobile phone, but a particular scanner device that supports Android applications.   Would you mind sending a link to the device home site?

It sounds like the device itself effectively has a 'keyboard' proxy that is the scanner itself, so that the application 'thinks' it is keyboard input.   In summary, you are trying to have the 'keyboard' only be the scanner (for one field), but Android is assuming that when you 'tap' on have focus on a field, then the field is 'keyboard enabled', so it is popping up the keyboard.

Is that a good summary?

Posted by mihai_neagoe on 15-Oct-2014 07:40

Indeed, it is a scanner device (Motorola MC40) with Android OS. I think the configuration of the phone allows to fill any input with the value from the scan. This works ok in the mobile application - what we are missing is to prevent the user from leaving the input field while doing a multple scan (by accidentally tap on a different part of the screen). And for this we checked a couple of solutions:

- on Scan event apply focus on the input field (as suggested as well - the problem here is that we cannot catch that event on this device; the BarcodeService events are not triggered)

- on tap event re-apply focus on the input field (this was the initial question - as the tap event is not catched either; only the tap hold event)

This thread is closed