Bug 28934

Summary: Add <input type=number> validation support
Product: WebKit Reporter: Kent Tamura <tkent>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: adele, darin, eric, hyatt, ian, michelangelo, pkasting
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
URL: http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#number-state
Bug Depends on:    
Bug Blocks: 19264, 27450, 27451    
Attachments:
Description Flags
Proposed patch
eric: review-
Proposed patch (rev.2)
none
Proposed patch (rev.3)
none
Proposed patch (rev.4) none

Attachments
Proposed patch (9.17 KB, patch)
2009-09-03 00:17 PDT, Kent Tamura
eric: review-
Proposed patch (rev.2) (9.21 KB, patch)
2009-09-03 02:08 PDT, Kent Tamura
no flags
Proposed patch (rev.3) (9.20 KB, patch)
2009-09-03 19:06 PDT, Kent Tamura
no flags
Proposed patch (rev.4) (8.18 KB, patch)
2009-09-04 02:18 PDT, Kent Tamura
no flags
Kent Tamura
Comment 1 2009-09-03 00:17:08 PDT
Created attachment 38969 [details] Proposed patch stringToFloat() is in HTMLInputElement.cpp because it will be used to parse min= max= step= attributes.
Eric Seidel (no email)
Comment 2 2009-09-03 01:21:51 PDT
Comment on attachment 38969 [details] Proposed patch It seems stringToFloat should have HTML5 in teh name. It's not a generic function, but rather a specific html5-compatible implementation. html5CompatStringToFloat html5SpecStingToFloat ? This would be better as a single if unless there is a grand plan to add a bunch more types... + switch (input->inputType()) { + case HTMLInputElement::NUMBER: + return !HTMLInputElement::stringToFloat(value, 0); + default: + return false; + } if (input->type() != HTMLInputElement::NUMBER) return false; // Check to make sure the number is valid, ignore the parsed number. return !HTMLInputElement::stringToFloat(value, 0); Otherwise looks fine.
Kent Tamura
Comment 3 2009-09-03 02:08:26 PDT
Created attachment 38976 [details] Proposed patch (rev.2) - Followed Eric's comments
Peter Kasting
Comment 4 2009-09-03 11:19:09 PDT
I disagree with Eric. Putting "HTML5" in function names is completely inappropriate given that this functionality will also be required for HTML 6, 7, ... and in fact HTML is switching to be unversioned (see e.g. "DOCTYPE HTML" and some of Hixie's comments). These functions should be called things like "userInputToDouble" or "inputStringToDouble" or something to indicate that the difference between them and a generic conversion to double is the fact that the origin is some kind of user input which needs additional validation or conversion. Also, nitpick: "numeber" -> "number" in at least one place.
Darin Adler
Comment 5 2009-09-03 12:59:36 PDT
(In reply to comment #4) > These functions should be called things like > "userInputToDouble" or "inputStringToDouble" or something to indicate that the > difference between them and a generic conversion to double is the fact that the > origin is some kind of user input which needs additional validation or > conversion. That sounds right to me too.
Ian 'Hixie' Hickson
Comment 6 2009-09-03 15:50:18 PDT
Putting "html5" in method or file names will just mean that a few years from now someone will have to go and rename the methods or files, just like we did recently with html4.css.
Kent Tamura
Comment 7 2009-09-03 19:06:56 PDT
Created attachment 39031 [details] Proposed patch (rev.3) Thank you for the comments. - toDoubleForHtml5() -> formStringToDouble() I didn't use "input" "user" because this method will be used for min= max= step= attributes. - Fix a typo
Kent Tamura
Comment 8 2009-09-04 02:18:51 PDT
Created attachment 39046 [details] Proposed patch (rev.4) - Resolve conflict with type=color.
Eric Seidel (no email)
Comment 9 2009-09-08 09:49:53 PDT
Comment on attachment 39046 [details] Proposed patch (rev.4) LGTM.
Eric Seidel (no email)
Comment 10 2009-09-08 10:00:55 PDT
Comment on attachment 39046 [details] Proposed patch (rev.4) Rejecting patch 39046 from commit-queue. This patch will require manual commit. ['WebKitTools/Scripts/run-webkit-tests', '--no-launch-safari', '--quiet', '--exit-after-n-failures=1'] failed with exit code 1
Eric Seidel (no email)
Comment 11 2009-09-08 10:02:48 PDT
Comment on attachment 39046 [details] Proposed patch (rev.4) Bitten by bug 29037.
Eric Seidel (no email)
Comment 12 2009-09-08 10:23:15 PDT
Comment on attachment 39046 [details] Proposed patch (rev.4) Clearing flags on attachment: 39046 Committed r48163: <http://trac.webkit.org/changeset/48163>
Eric Seidel (no email)
Comment 13 2009-09-08 10:23:20 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.