Opened 5 years ago
Last modified 3 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: |
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());
}
Change History (6)
comment:1 Changed 5 years ago by
| Owner: | set to pjungwir |
|---|---|
| Status: | new → pending |
comment:2 Changed 5 years ago by
| Status: | pending → new |
|---|
The Windows 7 Date/Time dialog works like this, as does the one in Xubuntu.
comment:3 Changed 5 years ago by
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 5 years ago by
| Milestone: | 1.9.0 → 1.11.0 |
|---|
comment:5 Changed 5 years ago by
| Keywords: | haspatch added |
|---|---|
| Status: | new → open |
comment:6 Changed 3 years ago by
| Milestone: | 1.11.0 → none |
|---|
Can you point to existing date pickers that have this behavior?