I'm experimenting with PhoneGap to develop some iPhone apps. PhoneGap basically wraps a UIWebView - it works well. The problem is the my app has several input fields that only take numeric input. I really need to force the numeric keypad instead of accepting the default standard keyboard, which then forces the user to switch to the numeric on every field. Does anyone know if this is possible? How?
Clarification: I know that Apple doesn't currently provide any API to allow this. I'm wondering if creating a custom class that inherited from UIWebView might help, or maybe creating a custom keyboard would open up some possibilities?
Update 6 Nov, 2009 - As noted below, Apple has recently updated safari functionality so that this is, once again, supported. So the accepted answer was changed to reflect that.
<html>
<input type='tel'/>
<input type='number'/>
<input type='email'/>
<input />
</html>
It looks like Mobile Safari supports the new HTML5 input type attributes of email, number, search, tel, and url. These will switch the keyboard that is displayed. See the type attribute.
So for example, you could do this:
And when the input box has focus, the number keyboard is shown (as if the user had the full keyboard and hit the "123" button.
If you really only want numbers, you could specify:
And then the user would get the phone number dialing keypad.
I know this works with Mobile Safari -- I only assume it will work with UIWebView.
From Apple's documentation (the note about UIWebView):
Checked on IPhone OS 3.0, this functionality was still not there, not sure why Apple just removed this handy functionality, really upset to work on this right now :(
iOs has a numeric keyboard
UIKeyboardTypeNumbersAndPunctuation
, but this can't be called from HTML (https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html)since on the "tel" keyboard the punctuation is missing you have to create this on your own. Since ios8 custom keyboards are available. Or if you just need the punctuation you can add a button (How to add a 'Done' button to numpad keyboard in iOS) to the numeric keyboard which pops up when you specify your input field with
type="number" pattern="[0-9]*"
.To do so: the objective-c code.
Then you should add the a method which can be accessed application wide in your JS code.
What you can also use for iOS phonegap based app is :
It is shown in the image below. Works beautifully with iOS 8.2 and phonegap 3.5 and above.
You need to make the change in the HTML portion of your Dashcode project:
type="text"
totype="number"
.Done.