Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DatePicker: How to pass array of years to the yearRange drop down

How do I pass an array of years to the yearRange, or to the year dropdown menu?

This question is related to the following post: jQuery DatePicker: currentDate does not work when the date field is 12-31-9999. The solution is to do 2000:c+1. But, the problem here is that the yearRange is from 2000 - 9999. This causes performance issues as it takes a few seconds to populate the year dropdown. Plus, the years 2020 - 9998 are not yet needed.

When a date field is 12-31-9999, I only want the yearRange to display 2000:+1 and the current year of 9999. So, the drop yearRange should provide the following years: 2000 - 2019, 9999.

like image 674
J Weezy Avatar asked Nov 07 '22 09:11

J Weezy


1 Answers

As per https://api.jqueryui.com/datepicker/#option-yearRange - according to the docs it's not possible. You can only set a single contiguous range.

But really this issue brings us directly back to the X-Y problem discussed in your earlier question - basically if your end dates were null instead of using a pretend date, you wouldn't have this issue in the first place. And your application's data quality would be better. I already know you don't want to hear that, but that's the root of the problem. If you can't change what's in the database, then at least remove these dates in the UI layer

like image 171
ADyson Avatar answered Nov 15 '22 06:11

ADyson