Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone input type (number with two decimals)

I'm developing an iphone application with phonegap, this means my application is in html5, javascript and css. I have a form with a field for weight on an object. I'm trying to get an input type similar to;

<input type="time"/>

Html5 supports different types of input, and this will toggle a different keyboard for the iphone, for example the numeric keyboard for numbers. The one I'm looking for is the one where you can roll vertically over numbers. Like when you set your alarm clock on the iphone, example below.

http://blog.ringtonefeeder.com/wp-content/uploads/2009/01/iphone-alarm.png

The input type="time" gives me that, but it's restricted to 24 hour window and 1-59 minute window.

Is there anyway to customize this input type so I can get a 2 decimal number? in the range of 0-999.99 kg.

I realize this is a vague question but it's hard to explain.

like image 214
Stefan Konno Avatar asked Apr 13 '12 20:04

Stefan Konno


People also ask

How do you type decimals on iPhone?

Here's a longer answer: on an iPhone, you enter decimals by pressing the +*# button in the lower-left corner of the keypad and pressing either * or #.

Can input type number accept decimal?

You can also use a decimal value: for example, a step of 0.3 will allow values such as 0.3, 0.6, 0.9 etc, but not 1 or 2. Now you don't get a validation error.

Does input type text allow numbers?

By default, HTML 5 input field has attribute type=”number” that is used to get input in numeric format. Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the input field that will popup numeric keyboard on mobile devices.

What is the input type for numbers?

<input type="number"> <input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries. The browser may opt to provide stepper arrows to let the user increase and decrease the value using their mouse or by tapping with a fingertip.


2 Answers

Have a look at inputmode="decimal" attribute.

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode

Not widely supported yet but it comes available in iOS 12.2.

https://caniuse.com/#feat=input-inputmode

like image 171
vguerrero Avatar answered Oct 28 '22 00:10

vguerrero


As far as I know, there's no way of doing this in the PhoneGap world. You can view the available keyboards here. You could probably roll your own if you're capable in objective-C, but then you'd have a create a plug-in for it so PhoneGap could see it.

One of the keyboards not shown on that page is: UIKeyboardTypeDecimalPad, which is a telephone keypad with just numerals and a decimal point, which might also work for your application. Shown here:

UIKeyboardTypeDecimalPad

However, I've been unable to figure out how to have it shown via HTML.

If you want the telephone keypad, you'd use:

<input type="tel">

Similarly if you wanted a numeric keypad, it'd be:

<input type="number">

As far as I know (and someone please correct me if I'm wrong), there's no equivalent for UIKeyboardTypeDecimalPad like this made up type:

<input type="decimalNumber">
like image 35
delliottg Avatar answered Oct 28 '22 01:10

delliottg