9

I know that there are many questions about that isssue already responded, but none of the solutions given has worked for me.

I'm developing a web for an enterprise that's using Samsung Galaxy Tab. There are lots of inputs which contents are decimal numbers. So I tried with <input type="number" />. But the navigator displays a keyboard with dot and comma disabled. Not only this, but onfocus, dot or comma separators are removed from the value.

I have already tried setting a step like "0,1", "0,01", "0.1", "0.01", "any", etc, tried min, max, pattern with a regex that matches decimal numbers... There are no advices in stackoverflow left to try, and this is terrible haha.

I'm using a Samsung Galaxy Tab 10.1 with default browser, but I haven't found any document talking about any limitation of it's html5 implementation. So nowadays I don't know if there is something I am missing, if there is something I can try, or if something knows that is Galaxy Tab's fault so I can do nothing for this.

Lots of thanks in advance.

Áxel Costas Pena
  • 5,886
  • 6
  • 28
  • 59
  • Have you tried installing Chrome on the tablet and using it to test the inputs? Installing Chrome and making it the default browser is the first thing I did on both of my Galaxy Tab 3 10.1 tablets. – Carl Von Stetten Jan 21 '14 at 18:00
  • I know that would be a hard requirement for the target team, we are not talking about "please stop using IE", but about "you have a lead product but you must anyway avoi using default browser". Thanks for the advice anyway. We finally ended up developing a simple custom HTML numeric keyboard. – Áxel Costas Pena Jan 22 '14 at 08:16
  • 2
    See this as a problem on Samsung Galaxy S3. Seems to be a problem with the 'Samsung keyboard' app, rather than the AOSP browser or Chrome. – contrebis Feb 20 '14 at 15:34
  • If you really want to improve the UX, and be sure it's working as expected on multiple platforms. You may better implement your own keyboard layout (in div). – Beeno Tung Dec 12 '18 at 06:12

3 Answers3

5

In android namespace you can use:

 android:inputType="numberDecimal"

Which enables you to input the "."

CocoNess
  • 4,213
  • 4
  • 26
  • 43
5

You need to extend your webview class and use its object like this

public class WebViewExtended extends WebView{

    public WebViewExtended(Context context) {
        super(context);
    }

    public WebViewExtended(Context context, AttributeSet attrs) {
        super(context, attrs);    
    }

    public WebViewExtended(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        InputConnection connection = super.onCreateInputConnection(outAttrs);
        if ((outAttrs.inputType & InputType.TYPE_CLASS_NUMBER) == InputType.TYPE_CLASS_NUMBER)
        {
            outAttrs.inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
        }

        return connection;
    }

}
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Syed Wajahat Ali
  • 541
  • 1
  • 7
  • 25
  • The question is about HTML5 > I'm developing a web for an enterprise that's using Samsung Galaxy Tab. There are lots of inputs which contents are decimal numbers. So I tried with – Áxel Costas Pena Oct 01 '14 at 07:53
  • @ÁxelCostasPena This is how you are going to get a dot in you numeric keypad. As androids latest versions don't have it in webview by default. The changes are to be made on the back end(android side) – Syed Wajahat Ali Oct 01 '14 at 09:21
  • Saved our day. Thank you. – Ivan Sivak Sep 17 '15 at 08:52
2

The HTML5 specification for input with a type of number states that any string that can be parsed as a valid floating point number should be allowed. That specifically includes . as well as -, + and e.

So the implementation on the Samsung Galaxy Tab 10.1 is invalid.

If you need to support this device, you may have to use type="text" and validate the string. This won't auto-pop the correct keyboard on devices that have software keyboards.

<input type="text" pattern="^-?(?:[0-9]+|[0-9]*\.[0-9]+)$" name="NumberInput">
Fenton
  • 241,084
  • 71
  • 387
  • 401
  • you meant to say implementation of `` on Android stock browser is invalid? – Mithun Sreedharan Sep 28 '12 at 08:31
  • @Mithun, that's what I can't believe, that either the html5 input type=number for the native browser of a Samsung Galaxy Tab is buggy, or the soft keyboard is nota dapted to floating point numbers, where no one outside is talking about that. – Áxel Costas Pena Sep 28 '12 at 08:43
  • @Áxel Try a different soft keyword and confirm the reproducibility – Mithun Sreedharan Sep 28 '12 at 08:58
  • You mean in the Samsung Galaxy Tab settings? In input settings have options "Swype", "Samsung Keyboard", "Android Spanish keyboard", and "Google Voice", but this doesn't solve the problem. What do you suggest me to do? Create afiddle with different examples to other owners of Galaxy Tab could reproduce it? – Áxel Costas Pena Sep 28 '12 at 09:23
  • It's a problem with the Samsung soft keyboard. Have seen it on multiple Samsung devices, but mostly on Galaxy Tabs. – oldwizard Apr 22 '14 at 12:26