Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultDate for datepicker is not working #57

Open
peterox opened this issue Apr 14, 2016 · 4 comments
Open

defaultDate for datepicker is not working #57

peterox opened this issue Apr 14, 2016 · 4 comments

Comments

@peterox
Copy link
Contributor

peterox commented Apr 14, 2016

When setting the datepickeroption 'defaultDate', the widget is being displayed with the current date instead of the 'defaultDate' .

To reproduce

  1. set the defaultDate to '01/03/2016'
  2. see that the calendar is displayed showing the current date instead.
peterox added a commit to MagicCarpetSoftware/jquery-ui-daterangepicker that referenced this issue Apr 14, 2016
@op16
Copy link
Contributor

op16 commented Apr 26, 2016

I don't know why do you need to use 'defaultDate'.

It's being used internally by our widget. If you want some date/range highlighted just set range as the value of the replaced input element.

@peterox
Copy link
Contributor Author

peterox commented Apr 27, 2016

My scenario is this.

  • I have made use of beforeShowDay() to highlight a date range as well as disable some days.
  • The range I have highlighted could be in the past
  • The date range the user must select is around the highlighted date range
  • The date range is optional

Currently without being able to set the defaultDate, when the user opens the date range picker the current day is displayed. The highlighted date range may not even be visible. This is a bad user experience.

You said 'If you want some date/range highlighted just set range as the value of the replaced input element.'. Do you mean that if I want a particular date range to be displayed then I should just set the initial date range to that value? If this is what you mean then that does not work for me as the date range is optional. Setting it to a pre-defined range would mean the user would need to click 'clear' which again is not a good user experience.

@op16
Copy link
Contributor

op16 commented Apr 27, 2016

The highlighted date range may not even be visible. This is a bad user experience.

I agree. That's why I had to use defaultDate in the first place, so that the pre-defined/ previously selected range is visible when the user opens the date range picker.

@dev-panpic
Copy link

Just test it work for me:
Case 1:

var start_date = moment().subtract('days', 1).startOf('day').toDate();
var end_date = moment().subtract('days', 1).startOf('day').toDate();
$("#e1").daterangepicker("setRange", {start: start_date, end: end_date});

Case 2:

var startDate = "{$php.startDate}";
var startDate = "{$php.endDate}";
var start_date = moment(startDate).subtract('days', 0).startOf('day').toDate();
var end_date = moment(endDate).subtract('days', 0).startOf('day').toDate();
$("#e1").daterangepicker("setRange", {start: start_date, end: end_date});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants