JQuery DatePicker: currentDate does not work when date field is 12-31-9999

DatePicker does not correctly handle the calculation of currentDate when the current field value is 12-31-9999 and yearRange is 2000: +1. The result for currentDate becomes 1-1-2000 when I click on the field to open the DatePicker. So it seems that DatePicker is moving the date to the beginning of the year. But if I delete yearRange, then the DatePicker will by default have a range from -10: +10, which will result in 9989: 10009 in the year.

I would rather show DatePicker today the date when I click on a field that contains 12-31-9999. Note: no changes are required when leaving the field. Is it possible?

$(".datePicker").datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", yearRange: 2000:+1 }); 
+1
source share
1 answer

The problem you are seeing is that the date in your input field ("9999-12-31") is outside the range you specified ("2000: +1"). This range gives dates from 2000-2019 (end of year - today is the year plus one, according to the specification).

You also said: "But if I delete yearRange, then the DatePicker will by default have a range from -10: +10." Not really. By default it is equal to β€œc-10: c + 10”, which, if you look at the specification, is not quite the same - β€œc” means that it puts a range of 10 years +/- year on the input, as opposed to present day.

I think this misunderstanding led to your mistake. If you want it to display the date 9999, set the range to year

 yearRange: "2000:c+1" 

This will set the maximum year as the year of input +1, unlike today's year +1.

See http://jsfiddle.net/5ornc4gv/7/ for a demo.

http://api.jqueryui.com/datepicker/#option-yearRange contains information about format strings.

As I noted in the comments, this would be a problem if your software used NULL to represent the β€œend date” of time periods without a real end date for the definition. Also, the drop-down list in yearpicker, which is released in your annual range, is difficult to use and may cause some lag in some browsers due to the amount of data in it.

+1
source

Source: https://habr.com/ru/post/1275715/


All Articles