Bug 161506 - [iOS] input pattern="[0-9.]*" should use DecimalPad keyboard
Summary: [iOS] input pattern="[0-9.]*" should use DecimalPad keyboard
Status: RESOLVED DUPLICATE of bug 183621
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari 9
Hardware: iPhone / iPad All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-01 13:29 PDT by Darryl Pogue
Modified: 2018-08-22 23:52 PDT (History)
11 users (show)

See Also:


Attachments
Patch (6.02 KB, patch)
2016-09-04 23:43 PDT, Darryl Pogue
beidson: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darryl Pogue 2016-09-01 13:29:29 PDT
Currently <input type="number" pattern="[0-9]*"> pulls up a UIKeyboardTypeNumberPad, which does not allow decimals. The alternative is to not specify a pattern and get the general numbers & punctuation keyboard.

It would be great to add support for pattern="[0-9.]*" to bring up a UIKeyboardTypeDecimalPad which includes a decimal key.


Unfortunately there isn't numeric-oriented keyboard that includes both a decimal and a negative sign, so we're stuck with UIKeyboardTypeNumbersAndPunctuation :(
Comment 1 Darryl Pogue 2016-09-04 23:43:34 PDT
Created attachment 287932 [details]
Patch
Comment 2 Darin Adler 2016-09-05 10:06:40 PDT
Seems like a reasonable improvement; the decision on this should be made by an iOS keyboards expert.
Comment 3 Alex Christensen 2016-09-05 23:09:35 PDT
Comment on attachment 287932 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=287932&action=review

I like this idea.  Can this be tested?

> Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:2517
> +static const char inputPatternNumber[] = "^(\\[0-9\\]|\\\\d)(\\+|\\*|\\{[0-9,]+\\})?$";
> +static const char inputPatternDecimal[] = "^(\\[0-9\\]|\\\\d)?(\\+|\\*|\\{[0-9,]+\\})?\\\\\\.(\\[0-9\\]|\\\\d)(\\+|\\*|\\{[0-9,]+\\})?$";

This is clever, but matching regular expressions with regular expressions seems like a step in the wrong direction.  We were doing string comparison before, which wasn't the greatest, but could we at least continue to do string comparison?
Comment 4 Darryl Pogue 2016-09-06 00:24:53 PDT
I agree the regex isn't an ideal solution. I was trying to brainstorm something more flexible than string comparisons though, and this was the best I came up with.

One complaint of the current string comparison whitelisting is that it makes it hard for people to use the pattern attribute for actual validations. If you want to collect a 5-digit number, the best pattern would be "\d{5}", but that causes iOS to opt-out of the number pad keyboard because it doesn't match the whitelist.


It's not obvious what the string comparison should be for a decimal pad, since the naïve "[0-9\.]*" would actually allow multiple decimal points to validate. Suggested patterns from online resources include "\d*\.\d*" or "[0-9]*\.[0-9]*", but both of those make the decimal point required.
Comment 5 Brad 2017-04-18 16:15:43 PDT
The testing of the regular expression with another regular expression seems much more useful to me than extreme limits that are there now.

I would like to use patterns like this:

\d+(\.\d*)?     // decimal number
\d+(\.\d{2})?   // dollars with optional cents
((\d+)?(\.\d{2})?)+   // optional dollar digits with optional cents

Etc. Or maybe an expression for validating IP addresses.
Comment 6 Brady Eidson 2018-02-14 10:34:05 PST
Comment on attachment 287932 [details]
Patch

Patches that have been up for review since 2016 are almost certainly too stale to be relevant to trunk in their current form.

If this patch is still important please rebase it and post it for review again.
Comment 7 Darryl Pogue 2018-02-14 10:49:45 PST
As an alternative to this (and of trying to use pattern to determine the correct keyboard in general), it might be better to add support for the `inputmode` attribute which would allow authors to specify a hint for which keyboard type to use:
https://html.spec.whatwg.org/multipage/interaction.html#input-modalities%3A-the-inputmode-attribute

There was a recent intent to ship for Blink/Chrome: https://groups.google.com/a/chromium.org/forum/#!searchin/blink-dev/inputmode/blink-dev/MAHQkH4vvUQ/i0yCobrMCQAJ
Comment 8 Dayton Lowell 2018-03-13 19:14:30 PDT
I’ve created a bug for adding `inputmode` support.

https://bugs.webkit.org/show_bug.cgi?id=183621
Comment 9 Darryl Pogue 2018-08-22 23:52:00 PDT
inputmode support was just merged, and provides a way to get a decimal keyboard via inputmode="decimal", so I'll close this as a duplicate of #183621

*** This bug has been marked as a duplicate of bug 183621 ***