Opened 10 years ago

Last modified 8 years ago

#8463 open feature

Option to set the date when changing month or year

Reported by: pjungwir Owned by: pjungwir
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.8.21
Keywords: haspatch Cc:
Blocked by: Blocking:


Right now, using the arrows or dropdowns to change the month & year does not actually effect the value of the date field: it just shows a new spread of dates to choose from. We've seen a lot of users get confused by this, so we would like an option to update the date field whenever the month or year changes. Currently we're implementing this with callbacks, but it seems worth offering this behavior as just an option. I'd be happy to write a patch if this is desirable. For reference, here are the callbacks we're using for now:

  onChangeMonthYear: function(year, month, datePicker) {
    // Prevent forbidden dates, like 2/31/2012:
    var $t = $(this);
    var day = $'preferred-day') || new Date().getDate();
    var newDate = new Date(month + '/' + day + '/' + year);
    while (day > 28) {
      if (newDate.getDate() == day && newDate.getMonth() + 1 == month && newDate.getFullYear() == year) {
      } else {
        day -= 1;
        newDate = new Date(month + '/' + day + '/' + year);
    $t.datepicker('setDate', newDate);
  beforeShow: function(dateText, datePicker) {
    // Record the starting date so that
    // if the user changes months from Jan->Feb->Mar
    // and the original date was 1/31,
    // then we go 1/31->2/28->3/31.
    $(this).data('preferred-day', ($(this).datepicker('getDate') || new Date()).getDate());

Change History (6)

comment:1 Changed 10 years ago by Scott González

Owner: set to pjungwir
Status: newpending

Can you point to existing date pickers that have this behavior?

comment:2 Changed 10 years ago by pjungwir

Status: pendingnew

The Windows 7 Date/Time dialog works like this, as does the one in Xubuntu.

comment:3 Changed 10 years ago by bernhardsirlinger

I have written the code for refreshing the input field every time the user selects a new value.

I already sent a Pull-Request on GitHub.

My GitHub Account is WebsiteDeveloper

comment:4 Changed 10 years ago by Scott González


comment:5 Changed 10 years ago by mikesherov

Keywords: haspatch added
Status: newopen

comment:6 Changed 8 years ago by Scott González

Milestone: 1.11.0none
Note: See TracTickets for help on using tickets.