tamble / jquery-ui-daterangepicker

A JQuery UI based date range picker.
MIT License
184 stars 110 forks source link

defaultDate for datepicker is not working #57

Open peterox opened 8 years ago

peterox commented 8 years ago

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.
op16 commented 8 years ago

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 commented 8 years ago

My scenario is this.

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 commented 8 years ago

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 commented 1 year ago

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});