Skip to main content

Search and Top Navigation

#8463 open feature ()

Opened July 26, 2012 09:41PM UTC

Last modified June 24, 2014 11:15PM UTC

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

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 = $t.data('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) {
        break;
      } 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());
  }
Attachments (0)
Change History (6)

Changed July 26, 2012 09:43PM UTC by scottgonzalez comment:1

owner: → pjungwir
status: newpending

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

Changed July 26, 2012 10:00PM UTC by pjungwir comment:2

status: pendingnew

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

Changed August 14, 2012 04:46PM UTC by bernhardsirlinger comment:3

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

Changed October 11, 2012 02:45PM UTC by scottgonzalez comment:4

milestone: 1.9.01.11.0

Changed October 19, 2012 10:18PM UTC by mikesherov comment:5

keywords: → haspatch
status: newopen

Changed June 24, 2014 11:15PM UTC by scottgonzalez comment:6

milestone: 1.11.0none