Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type=number not possible to insert negative numbers on mobile phone

I'm testing my app on my mobile phone (samsung galaxy note II with chrome) and I have a problem with the numeric input fields.

In my app these fields can accept negative numbers, and on the browser it's all fine as I have the - button and also the arrow sliders (from html5) for choosing the number.

On the phone though the sliders are not rendered, and the browser recognise the input type=number, and just renders a simplified numeric keyboard, which doesn't contain the - sign, so I didn't see a way to insert the negative number I wish.

My app uses twitter bootstrap 2.3.2 with jquery, I'm not sure how to solve this problem.

here's the code for one of my input fields that work fine on my computer, but can't use them properly on my phone:

<input class="input-mini" data-type="distance_price" id="distance" label="false" name="distance" step="0.1" type="number" max="-0.1">

screenshot from my phone

in the image you can see how the field in red is marked as wrong because it needs to be negative, but my keyboard doesn't let me insert symbols. including the - sign. any clue?

like image 831
Don Giulio Avatar asked Feb 10 '14 12:02

Don Giulio


People also ask

Does input type number allow negative?

The number input type can accept both positive and negative integers as well as floating point numbers. The first element accepts integers from one to twenty.

How do you not allow negative values in input type numbers?

Solutions with HTML attributes As we know, the <input type="number"> specifies a field for entering a number. If you want to restrict the <input> field to only positive numbers, you can use the min attribute.

How do you type negative numbers?

Negative numbers are usually written with a minus sign in front. For example, −3 represents a negative quantity with a magnitude of three, and is pronounced "minus three" or "negative three".

What does do not allow negative numbers input react?

You can add an onKeyPress listener to the input element and that will be triggered before the onChange and call a function that will prevent default behaviour when the minus button is pressed.


1 Answers

If you use the value attribute (value="-0.1") to load an initial negative value then you will have the minus sign pre-loaded for you.

<input class="input-mini" data-type="distance_price" id="distance" label="false" name="distance" step="0.1" type="number" max="-0.1" value="-1">
like image 183
craigmc_2000 Avatar answered Oct 05 '22 22:10

craigmc_2000