Hello,
May I please ask if anyone could advise how to create a date picker with a date range selection?
In the posted file, I have a mockup design for a single date selection that supports automatic snapping of the highlighted date to the current date in user’s calendar.
I was wondering if there is an option to augment this design (on the left) with an option to select a date range (on the right).
I created this widget a while back as an exercise (also initially based on @mbc66’s date range picker). I made the following changes to it:
A range can be a single day
A range can span months (though the UX of this model is iffy at best)
The calendar starts off with the current month and you can go to next/previous months
Clicking within the date range resets the range: otherwise, you can never pick a start date that’s within the range without resetting (see note below on how this could be better)
Clicking the start/end dates (above the calendar) navigates to the appropriate month
The dateCell DP has just one state.
Got rid of the mouse-over states, due to bugs dealing with such states in repeaters…
It doesn’t write to (or read from) the repeater’s dataset, so it’s more performant
I won’t attempt to explain how it works beyond this: there’s a lot of date math and conditional logic, both in OnClick of the date (which sets the “variables” indicating the range) as well as in OnItemLoad (which draws the range based on those variables)
Note: a better solution for this click-within-the-range issue might be to update the start date when the clicked date is closer to the start date than it is to the end date, else update the end date with the clicked date.
[Edit] Got rid of some unnecessary tests in the conditional logic (in OnItemLoad) and added display of the current date. I updated the preview as well:
One last update: I added a second page that has the same deal except with ghosted days from the previous/next month. I’m not sure whether it makes a range that spans months more or less confusing! The performance is degraded a bit; I’d hate to see it in IE!