Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Select range #139

Open
Davecave opened this issue Apr 4, 2018 · 4 comments
Open

Select range #139

Davecave opened this issue Apr 4, 2018 · 4 comments

Comments

@Davecave
Copy link

Davecave commented Apr 4, 2018

I like the datepicker very much because it's easy to use and looks nice.
But I'm really missing a range functionality. Do you consider to integrate something like that?

<input id="start" data-toggle="datepicker"> <input id="end" data-toggle="datepicker">
Right now you can enter a date in the second one which is prior to first one, which of course shouldn't be the case if you want to enter a range.

Additionally highlighting the selected range in the second field would be useful.

@webdo
Copy link

webdo commented Aug 9, 2018

If you only use two dates on one page its pretty easy to do.

$('#startDate').datepicker();
$('#endDate').datepicker({
	filter: date => { return (new Date($('#startDate').val()) >= date) ?  false : true; } 
});

@chrislawes79
Copy link

Or you could use a date-range picker made specifically to do this

@linxiaowang
Copy link

If you only use two dates on one page its pretty easy to do.

$('#startDate').datepicker();
$('#endDate').datepicker({
	filter: date => { return (new Date($('#startDate').val()) >= date) ?  false : true; } 
});

your method only suits click startDate first, what if i want click the endDate first sometimes, then the startDate can select a later date, how to solve this? (╹▽╹)

@linxiaowang
Copy link

linxiaowang commented Dec 9, 2019

If you only use two dates on one page its pretty easy to do.

$('#startDate').datepicker();
$('#endDate').datepicker({
	filter: date => { return (new Date($('#startDate').val()) >= date) ?  false : true; } 
});

your method only suits click startDate first, what if i want click the endDate first sometimes, then the startDate can select a later date, how to solve this? (╹▽╹)

already figure it out. not so familiar with the document (#^.^#)
$('#startDate').on('pick.datepicker', function (e) { $('#endDate').datepicker('setStartDate', $('#startDate').datepicker('getDate')); });

$('#endDate').on('pick.datepicker', function (e) { $('#startDate').datepicker('setEndDate', $('#endDate').datepicker('getDate')); });

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

No branches or pull requests

5 participants