Ticket #9689 (closed bug: notabug)

Opened 9 months ago

Last modified 8 months ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 9 months ago by tj.vantoll

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.

comment:2 Changed 9 months ago by scott.gonzalez

  • Status changed from new to closed
  • Resolution set to notabug

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.

comment:3 Changed 9 months ago by machineghost

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.

comment:4 Changed 9 months ago by scott.gonzalez

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?

comment:5 Changed 8 months ago by tj.vantoll

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 :)

Note: See TracTickets for help on using tickets.