Skip to main content

Search and Top Navigation

#9689 closed bug (notabug)

Opened December 04, 2013 07:28PM UTC

Closed December 06, 2013 02:28PM UTC

Last modified December 10, 2013 01:43PM UTC

Entering unusual date format and hitting enter in datepicker results in today's date

Reported by: machineghost Owned by:
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.10.3
Keywords: Cc:
Blocked by: Blocking:
Description

Reproduction Steps:

1. Start with a datepicker (eg. the one at http://jqueryui.com/datepicker/)

2. Enter the text "2011/08/05" and press enter

3. Rather than A) converting the date to the proper format, B) clearing the text field as invalid, or C) alerting the user, the datepicker does D) replace the entered date with today's date (and if the user is unobservant they won't even realize that their date was replaced)

Conversely, if you do the same exact thing, except hit "tab" (or click away or otherwise lose focus) instead of hitting "enter" the entered string remains in the datepicker.

I'm not sure what the right behavior is (converting the date would seem correct, but I don't know what formats the datepicker officially supports), but silently replacing the user-entered date with another date is definitely the wrong behavior.

Attachments (0)
Change History (5)

Changed December 06, 2013 02:19PM UTC by tj.vantoll comment:1

Hi machineghost,

Thanks for taking the time to contribute to the jQuery UI project. I'll respond to each of these individually.

A) converting the date to the proper format

The datepicker only knows of one format. If the date is in that format, it can't guess at other ones. You could add that behavior yourself.

B) clearing the text field as invalid,

I think this would be equally confusing to the user.

C) alerting the user, the datepicker does

You could add this, but it isn't something the datepicker is going to do for everyone.

D) replace the entered date with today's date (and if the user is unobservant they won't even realize that their date was replaced)

The enter key selects the currently focused date, and unless you type a valid date, it remains today's date - which is why the current behavior occurs.

The only alternative behavior in my opinion is to not do anything, i.e. if the user types a bad date and presses enter nothing happens. I could go either way so I'll ask for some other opinions.

Changed December 06, 2013 02:28PM UTC by scottgonzalez comment:2

resolution: → notabug
status: newclosed

I agree with everything @tj.vantoll said. The behavior of pressing enter is tricky though since it can mean one of two things: 1) select the currently focused date; 2) submit the form. I think if the datepicker is open, it has to select the date, just like autocomplete when the menu is open. So I agree that there's nothing to change here. If you don't want this behavior, you should be able to bind an event handler to suppress the behavior.

Changed December 09, 2013 11:44PM UTC by machineghost comment:3

I honestly think leaving the date the user typed in is much better than SILENTLY changing it on them (if it wasn't silent this wouldn't be a bug IMHO), but thanks for your time.

Changed December 10, 2013 01:06AM UTC by scottgonzalez comment:4

I think it's too late to change the behavior of the current implementation, but we can certainly change the behavior with the rewrite. Looking at Chrome, you're either typing in the input OR navigating. Pressing enter while the datepicker is open only selects the date, it does not close the datepicker. I think this is a good model. @tj.vantoll Do you want to update the planning wiki based on how Chrome behaves?

Changed December 10, 2013 01:43PM UTC by tj.vantoll comment:5

I agree that Chrome's implementation is ideal here; I noted it on the wiki http://wiki.jqueryui.com/w/page/12137778/Datepicker.

I thought I'd be able to just implement this in the rewrite as well, but it turned out to be trickier than I anticipated. So for now it's just a note :)