wakirin / Litepicker

Date range picker - lightweight, no dependencies
MIT License
899 stars 132 forks source link

Dropdown contains un-selectable dates #199

Closed onelazydev closed 2 years ago

onelazydev commented 3 years ago

The year dropdown can display unexpected values, depending on settings which I will outline below in multiple use cases.

Displayed dates not within drop down values

Example : https://jsfiddle.net/MrMarlow/gbf0so95/

This example outputs last month and this month of the current year, even though the the minDate and maxDate are both last year.

In this instance, I would perhaps expect Jan 2020 as the first block, since it's the first month in the range.

Single month date range display?

Example : https://jsfiddle.net/MrMarlow/tdkx8acs/

I accept this is probably preference, but from a design perspective I would expect the above example to return January 2020 as the first panel, with Feb 2020 as the second. As the single month is the target for display, it should be the first month displayed?

This is amplified as a problem for the third example below.

Max year wrong for single month date range, with splitView

Example: https://jsfiddle.net/MrMarlow/Lrutv6wo/

As above, the solution to this would be to move the first month (minDate) to the first of the 2 months on show as adding splitView actually adds another year to the second month for some reason, showing 2021 in the example, rather than 2020.

Extension of above

If you extend to 2 months, the expected result would be the 2 selected months on display as the initialised view, however the year in the second view remains one year ahead of the first calendar, like in this example: https://jsfiddle.net/MrMarlow/4qhs9ob5/


If you need any more information from me, do ask.

wakirin commented 3 years ago

Displayed dates not within drop down values

This case can be fixed with maxDate: '2020-12-31'

In this instance, I would perhaps expect Jan 2020 as the first block, since it's the first month in the range.

In the next release, if you provide both options (minDate, maxDate), the calendar will be displayed with minDate. (but if the range contains the current month, the calendar will display the current month). Currently if you need to go to a specific date, you can use gotoDate, for example:

...
  setup: (picker) => {
    picker.gotoDate('2020-01-01')
  }
....

Single month date range display?

Max year wrong for single month date range, with splitView

These cases will be fixed in the next release.

Thanks for the detailed information.

onelazydev commented 3 years ago

Hey there!

I have gone through your response and just have one further inconsistency with the documentation I've found.

Displayed dates not within drop down values

Example: https://jsfiddle.net/MrMarlow/bafprdvh/

If you provide a format (format: "DD/MM/YYYY",) and then add maxDate with that format (maxDate: '31/12/2020',), the code does not appear to account for that, as per the documentation which states: Date Object or Unix Timestamp (with milliseconds) or String (must be equal to option format).

If I use date time format (YYYY-MM-DD), it works as expected - so maybe this is a documentation change?

Thanks for the speedy response and solutions. I look forward to your next release.

Appreciate the work you've done for this date picker, it's been a breeze to work with.

wakirin commented 3 years ago

Yes, good point. I will update the docs.

onelazydev commented 3 years ago

Hey again @wakirin,

On further inspection today, as I am fiddling with the picker again, I realised that maxDate also doesn't appear to take the UK date format (DD/MM/YYYY) into consideration, but rather just disregards it.

Example: https://jsfiddle.net/MrMarlow/or6ngep7/

Changing this to either the date format (YYYY-MM-DD) or US date format (MM/DD/YYYY) will parse it right, whether you change the format setting or not.

wakirin commented 3 years ago

@MrMarlow I will update the docs about it. New description for minDate, maxDate will be:

Date Object or Unix Timestamp (with milliseconds) or ISO String.

wakirin commented 3 years ago

v2.0.11

Displayed dates not within drop down values

https://jsfiddle.net/nxuqfb7p/

For correct view required to add minDate and maxDate.

Single month date range display?

https://jsfiddle.net/xjv7Lmts/

Max year wrong for single month date range, with splitView

https://jsfiddle.net/q0y4uvfc/


Docs updated too.

https://litepicker.com/docs/options#maxdate https://litepicker.com/docs/options#mindate