Closed
Bug 1372369
Opened 7 years ago
Closed 7 years ago
I can enter 31/02/2017 (pt-br) as a date
Categories
(Core :: Layout: Form Controls, enhancement)
Tracking
()
VERIFIED
FIXED
mozilla56
Tracking | Status | |
---|---|---|
firefox56 | --- | verified |
People
(Reporter: alex.fdm, Assigned: jessica)
References
(Blocks 1 open bug)
Details
Attachments
(2 files, 1 obsolete file)
6.92 KB,
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
24.40 KB,
patch
|
jessica
:
review+
|
Details | Diff | Splinter Review |
I was trying the new date form controls, and it does a fair job of restricting the inputs. But I was able to enter 31/02/2017 (in pt-br) as a date with no complaints.
What was the value you entered? The summary says "31-02-217" and comment 0 says "31/02/2017".
Assignee | ||
Comment 2•7 years ago
|
||
I think reporter means "31/02/2017" in pt-br.
We avoid setting invalid value to the input element's .value property, otherwise, the value would become empty after sanitizing. But yes, we do need to inform the user about this, so I think we need a way to set validity state to "bad input" (This is what Chrome does too after entering 31/02/2017).
Assignee | ||
Updated•7 years ago
|
Assignee: nobody → jjong
Summary: I can enter 31-02-217 as a date → I can enter 31/02/2017 (pt-br) as a date
Reporter | ||
Comment 3•7 years ago
|
||
let me try to elaborate some more...
- I only entered the digits, it was automatically formatted to 31/02/2017. Yes, the title was wrong. Sorry.
- This issue is about accepting invalid dates, not about the formatting.
- I gave one extreme example, but it is not the only invalid date that is accepted. Other accepted dates: 29/02/2100 (not a leap year), and 31/04/2017 (April has only 30 days).
Assignee | ||
Comment 4•7 years ago
|
||
In this patch, we change it so that we always set the input element's value
once all fields are available and let DOM HTMLInputElement sanitize it. The
value after sanitization is not updated in the displayed input box, but may
display an error message (this will be done in Part 2) if needed.
Also, when any of the field's value is deleted, we will set input element's
value back to the empty string, so that a value is not accidentally submitted.
Attachment #8878393 -
Flags: review?(bugs)
Assignee | ||
Comment 5•7 years ago
|
||
If all fields in date/time input box are available but the input element's
value is empty, implies that it has been sanitized. In this case, we'll set the
'bad input' vailidty state. If any of the fields is cleread, we'll remove the
'bad input' validity state, as incomplete field does not imply 'bad input'.
Attachment #8878394 -
Flags: review?(bugs)
Comment 6•7 years ago
|
||
Comment on attachment 8878393 [details] [diff] [review]
Part 1: Update input element's value when all fields are entered.
This would need some manual testing too, to see the ux. I didn't do that.
Attachment #8878393 -
Flags: review?(bugs) → review+
Comment 7•7 years ago
|
||
Comment on attachment 8878394 [details] [diff] [review]
Part 2: Set validity state to 'bad input' when the entered date value is invalid.
># HG changeset patch
># User Jessica Jong <jjong@mozilla.com>
># Parent 38ec76213d854d60628be397d5f3d43e3fe4fc84
>Bug 1372369 - Part 2: Set validity state to 'bad input' when the entered date value is invalid. r=smaug
>
>If all fields in date/time input box are available but the input element's
>value is empty, implies that it has been sanitized. In this case, we'll set the
>'bad input' vailidty state.
validity
If any of the fields is cleread, we'll remove the
cleared
>@@ -7629,16 +7643,18 @@ HTMLInputElement::GetValidationMessage(n
> case VALIDITY_STATE_BAD_INPUT:
> {
> nsXPIDLString message;
> nsAutoCString key;
> if (mType == NS_FORM_INPUT_NUMBER) {
> key.AssignLiteral("FormValidationBadInputNumber");
> } else if (mType == NS_FORM_INPUT_EMAIL) {
> key.AssignLiteral("FormValidationInvalidEmail");
>+ } else if (mType == NS_FORM_INPUT_DATE && IsInputDateTimeEnabled()) {
>+ key.AssignLiteral("FormValidationInvalidDate");
So we don't need to care about time or week or month or datetime here, only date?
Please add a comment.
Attachment #8878394 -
Flags: review?(bugs) → review+
Assignee | ||
Comment 8•7 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #6)
> Comment on attachment 8878393 [details] [diff] [review]
> Part 1: Update input element's value when all fields are entered.
>
> This would need some manual testing too, to see the ux. I didn't do that.
I did some basic manual testing, looks ok. After both patches, the red box shows up when user enters an invalid value, e.g. Jun 31 2017, and the red box disappears when all or any of the fields value is removed.
(In reply to Olli Pettay [:smaug] from comment #7)
> Comment on attachment 8878394 [details] [diff] [review]
> Part 2: Set validity state to 'bad input' when the entered date value is
> invalid.
>
> ># HG changeset patch
> ># User Jessica Jong <jjong@mozilla.com>
> ># Parent 38ec76213d854d60628be397d5f3d43e3fe4fc84
> >Bug 1372369 - Part 2: Set validity state to 'bad input' when the entered date value is invalid. r=smaug
> >
> >If all fields in date/time input box are available but the input element's
> >value is empty, implies that it has been sanitized. In this case, we'll set the
> >'bad input' vailidty state.
> validity
>
> If any of the fields is cleread, we'll remove the
> cleared
Thanks, will correct the typos.
>
> >@@ -7629,16 +7643,18 @@ HTMLInputElement::GetValidationMessage(n
> > case VALIDITY_STATE_BAD_INPUT:
> > {
> > nsXPIDLString message;
> > nsAutoCString key;
> > if (mType == NS_FORM_INPUT_NUMBER) {
> > key.AssignLiteral("FormValidationBadInputNumber");
> > } else if (mType == NS_FORM_INPUT_EMAIL) {
> > key.AssignLiteral("FormValidationInvalidEmail");
> >+ } else if (mType == NS_FORM_INPUT_DATE && IsInputDateTimeEnabled()) {
> >+ key.AssignLiteral("FormValidationInvalidDate");
> So we don't need to care about time or week or month or datetime here, only
> date?
> Please add a comment.
Sorry, I forgot to mention this. For the two input types (date and time) that we support now, only date may have bad input, since with input time, we forbid or autocorrect values that are not in the valid range. For example, in 12hr format, if users enter 2 in the hour field, it will be treated as 02 and advance to the second field; in 24hr format, if user enters 25 in the hour field, it's automatically corrected to 23 and advance to the second field.
Assignee | ||
Comment 9•7 years ago
|
||
(In reply to Jessica Jong [:jessica] from comment #8)
> Sorry, I forgot to mention this. For the two input types (date and time)
> that we support now, only date may have bad input, since with input time, we
> forbid or autocorrect values that are not in the valid range. For example,
> in 12hr format, if users enter 2 in the hour field, it will be treated as 02
> and advance to the second field; in 24hr format, if user enters 25 in the
Sorry, should be "minute field" in both of the cases above.
Assignee | ||
Comment 10•7 years ago
|
||
Fixed typos, added comments and some more tests.
Attachment #8878394 -
Attachment is obsolete: true
Attachment #8879039 -
Flags: review+
Assignee | ||
Comment 11•7 years ago
|
||
Keywords: checkin-needed
Comment 12•7 years ago
|
||
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/197dee6bc476
Part 1: Update input element's value when all fields are available and let DOM HTMLInputElement sanitize it. r=smaug
https://hg.mozilla.org/integration/mozilla-inbound/rev/b9a984aa8176
Part 2: Set validity state to 'bad input' when the entered date value is invalid. r=smaug
Keywords: checkin-needed
Comment 13•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/197dee6bc476
https://hg.mozilla.org/mozilla-central/rev/b9a984aa8176
Status: NEW → RESOLVED
Closed: 7 years ago
status-firefox56:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
Comment 14•7 years ago
|
||
Verified as fixed on Firefox Nightly 56.0a1(2017-06-20 build) on Windows 10 x 64, Mac OS X 10.12 and Ubuntu 16.04 x64.
When entering "31/02/2017" value, the input box becomes red and on hover, the "Please enter a valid date" message appears.
Status: RESOLVED → VERIFIED
Reporter | ||
Comment 15•7 years ago
|
||
I tested with other edge cases, they all seem OK.
29/02/2000 (leap year)
29/02/2017 (not a leap year)
29/02/2100 (not a leap year)
31/06/2017 (June has only 30 days)
You need to log in
before you can comment on or make changes to this bug.
Description
•