Samsung Galaxy Tablet does not allow entering floating point numbers to inputs with “number” type

荒凉一梦 提交于 2019-12-29 08:28:10

问题


Our client wants us to display numeric keyboard for an input field so basically I created a field like:

<input type="number" name="quantity" step=".01" value="0.00" />

However, Galaxy Tablet erases "." and merges numbers before and after it, also disables "." in the keyboard.

Is there another way to solve this issue or display numeric keyboard in input field when using type="text"?

Note: I tried using pattern attribute (which works on iPhone). I tested this issue on various Android devices with Android 2.1+. I did not encounter this error on any other HTC and Samsung devices.


回答1:


Yes, there is another way.

  1. Way 1: don't use type="number" but use type="text"
  2. Way 2: Apply way 1 for only Android phones. Detect User-Agent etc.
  3. Way 3: Apply way 1 for only broken implementations. See: What models of Samsung smartphones have missing period for html5 input type="number"?
  4. Way 4: Use type="tel"' for only Android or broken. (can't use on iPhone as no period then)
  5. Way 5: use type="text" and then javascript with custom behavior. See:

Period always shows: http://jsbin.com/heqeduyi/1/

Period shows once 3 digits: http://jsbin.com/yinaweho/1




回答2:


A workaround is to use type="tel" instead of type="number". Unfortunately on iOS type="tel" doesn't display the , char on the keyboard (at least I didn't find it there). You can check the user agent for iOS devices and then change type on "number".




回答3:


Did you try setting step to "any". Like:

<input type="number" name="quantity" step="any" />

I took out the "value" because I think you should, even if just for testing




回答4:


I do this in C#/Xamarin and what works for me on the code side (I dynamically build up forms) is using the following:

   EditText edittext1 = new EditText(view.Context);
   edittext1.InputType = Android.Text.InputTypes.NumberFlagDecimal;

Hope it helps someone




回答5:


To have decimal point in the numeric keyboard on Android Samsung devices use this in you EditText:

 android:inputType="numberDecimal"


来源:https://stackoverflow.com/questions/11134903/samsung-galaxy-tablet-does-not-allow-entering-floating-point-numbers-to-inputs-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!