Skip to main content

Search and Top Navigation

#6123 closed bug (notabug)

Opened September 29, 2010 01:11PM UTC

Closed October 18, 2012 05:26PM UTC

Datepicker: strange interaction with yearRange and defaultDate

Reported by: fokeyjoe Owned by:
Priority: minor Milestone: 1.11.0
Component: ui.datepicker Version: 1.8.4
Keywords: yearRange defaultDate Cc:
Blocked by: Blocking:
Description

I'm trying to get the datepicker to give a list with the yearRange c-100:c-18 (employee dob's, and could be outside the range so min/maxDate not relevant). By default it shows 1910 (I guess because the latest year), but I want it to show 1992 by default, but I can't get it to, and I think it might be a bug due to the base date chosen when the current year isn't available.

Initially, I started with:

$("input[name='datepicktest']").datepicker({
  dateFormat : 'dd-mm-yy',
  gotoCurrent: true,
  changeYear: true,
  yearRange: "c-100:c-18"});

I tried to work around it with:

var defDate = new Date();
defDate.setYear(defDate.getFullYear()-18);
$(document).ready(function () {
    $("input[name='datepicktest']").datepicker({
        dateFormat : 'dd-mm-yy',
        gotoCurrent: true,
        changeYear: true,
        defaultDate: defDate,
        yearRange: "c-100:c-18"
    });
});

But this workaround shows a date of 1892, and the year list changes to go down. If I replace -18 in defDate with +82, I get 1992 as the default, but the list of years is then incorrect.

The workaround I can go with is the latter with a yearRange of c-100:c+0, then the defaultDate seems to work properly.

Attachments (0)
Change History (3)

Changed September 29, 2010 01:20PM UTC by fokeyjoe comment:1

Sorry.. think I confused myself, my last workaround does exactly what I want, and I can see why, yearRange is relative to defaultDate. I guess it was just the way it switched to a different date when yearRange was not inclusive of the defaultDate. I'm not sure if that should be fixed or not - maybe just a note in the docs?

Changed October 11, 2012 09:04PM UTC by scottgonzalez comment:2

milestone: TBD1.11.0

Changed October 18, 2012 05:26PM UTC by mikesherov comment:3

resolution: → notabug
status: newclosed