Ethan Zheng
Ethan Zheng

Reputation: 21

Is there a way to block the soft keyboard when an input get focus on phonegap?

Is there a way to block the soft keyboard when an input get foucs, but DO NOT lose the input's focus (keep the cursor in the input filed)?

I'm programming a phonegap application on android. I have to show a custom keyboard, which is not an IME, just is an android activity, paint as a soft keyboard(for some reason, I can change this solution). The problem is that when the input get focus, the custom keyboard and system's soft keyboard(IME) both are displayed. Can I block the system's soft keyboard ?

Hum, it's a phonegap application and the input is a HTML input and sorry for my poor English.

Upvotes: 2

Views: 4701

Answers (2)

BardiaD
BardiaD

Reputation: 119

Had a similar situation myself on a current cordova/backbone app we're working on.

Our situation:

We had datepicker / timepicker plugins we were using with JQuery. These plugins provided their own interface for selecting and inputting time/date values. However whenever an input field for a date or time picker gained focus the soft-keyboard would be revealed. This was confusing, as the user is expected to input data via the onscreen calendar/time dial and not the softkeyboard.

Solution

Our solution for this was to add the readonly attribute to our <input>'s. Since we were setting these values programmatically, there was no reason to make these inputs read/write fields. From our experience it seems that setting a field to readonly will prevent the soft keyboard from showing up when those input fields receive focus

Upvotes: 1

BenAtack
BenAtack

Reputation: 98

In config.xml add the following preferences:

  <preference name="android-windowSoftInputMode" value="stateHidden"/>

other examples here:

http://developer.android.com/guide/topics/manifest/activity-element.html

android:windowSoftInputMode=["stateUnspecified",
                             "stateUnchanged", "stateHidden",
                             "stateAlwaysHidden", "stateVisible",
                             "stateAlwaysVisible", "adjustUnspecified",
                             "adjustResize", "adjustPan"] >

In answer to op's comment:

See this: How can I hide the Android keyboard using JavaScript?

Upvotes: 0

Related Questions