uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.66k stars 6.08k forks source link

DateRange does not get inputs dates when initialized #1210

Open guypaskar opened 9 years ago

guypaskar commented 9 years ago
to

and I init the daterange like this: $('.page-date-selection').datepicker( {showTime:true,autoclose:true} )

after that I do

$('#start-date').datepicker('update',someDateString); $('#end-date').datepicker('update' someDateString)

The pickers has the right values but I do not see the range selected within them. Only after I manually select a date on the date picker the range is being updated visually.

Any ideas? screen shot 2014-12-22 at 5 37 55 pm

arjenzwerver commented 9 years ago

I also posted this solution in issue #1000. Hopefully it works for you:

$("#datePicker.input-daterange").data("datepicker").pickers[0].setDate(new Date()); $("#datePicker.input-daterange").data("datepicker").pickers[1].setDate(new Date());

guypaskar commented 9 years ago

So on my cone it can look like this right?

$(".page-date-selection").data("datepicker").pickers[0].setDate(sDate); $(".page-date-selection").data("datepicker").pickers[1].setDate(eDate);

This did not work for me. The date was not selected even in the date picker (the right date was not displayed)

arjenzwerver commented 9 years ago

Yes, but the div containing the input dates should have the class: "input-daterange". Otherwise the datepicker doesn't know that it has to do something with a range.

Maybe that's not neccesarry when defining the inputs manually. $("#datePicker.input-daterange").datepicker({ ... inputs: $("#datePicker.input-daterange .input-group") });

guypaskar commented 9 years ago

Here is the div, it has input-daterange class.

I'm not sure I follow what you meant by Maybe that's not neccesarry when defining the inputs manually. $("#datePicker.input-daterange").datepicker({ ... inputs: $("#datePicker.input-daterange .input-group") });

arjenzwerver commented 9 years ago

The datepicker doesn't know if it has to render as a rangepicker. If you specify the class input-daterange, then it knows you're talking about a range. Otherwise you should specify the inputs manually like the code I mentioned.

Because it finds multiple input fields it also knows that it has to be a rangepicker.

guypaskar commented 9 years ago

I see. The parent div has input-daterange class.

So I tried the initial code and it did not work for me... did not even change the datepicker itself..

arjenzwerver commented 9 years ago

I made a jsfiddle, hopefully that helps.

http://jsfiddle.net/zcdbtb00/3/

natsu90 commented 9 years ago

thanks @arjenzwerver, works for me.

SlinkyPotato commented 8 years ago

Works perfectly as described, this is exactly what I was looking for. Thanks!