Setting selectable ranges in date element

JennaMar

Member
Hello,
i want to set the calendar to make only specific dates selectable. Have tried to change the examples but cannot get it to work.

Think it has to start like this, but no clue how to go on.

var startDate = new Date('2016-04-18');
var endDate = new Date('2016-04-29');

Hope you can help me. Thanks in advance
JennaMar

Maybe my title causes problems.
I want every single day between startDate and endDate to be selectable, so no range.
 
Last edited:
shouldn't it work with a php snippet, like this?
$data->dateAllow('2016-04-18', '2016-04-29');



var allowedDates = ['2016, April 18','2016, April 29'];
var result = true;
date = new Date(date);
if (typeOf(allowedDates) !== 'null') {
for (i = 0; i < allowedDates.length; i++) {
var td = new Date(allowedDates);
if (date.getUTCFullYear() == td.getUTCFullYear() && date.getUTCMonth() == td.getUTCMonth() && date.getUTCDate() == td.getUTCDate()) {
// A date has been found.
result = false;
}
}
}


this is what works for me
now i want only april to be shown.
any idea?
 
Last edited:
Code:
var startDate = new Date('2016-04-18');
var endDate = new Date('2016-04-29');
var thisDate - new Date(date);
var result = startDate <= thisDate && thisDate <= endDate;

-- hugh
 
oh yes, thanks a lot. think my code makes loading lot slower.

calendar is not loading anymore

ok there was a - not a =
now the range which should be selectable is disabled
will result=false fixe something here?
 
Last edited:
WIKI says
Set a variable called 'result' to true to stop/prevent this date from being selected.
Set a variable called 'result' to false to allow this date to be selected
So yes, I think the logic should be the other way. Just try.
 
Code:
var startDate = new Date('2016-04-18');
var endDate = new Date('2016-04-29');
var thisDate = new Date(date);
var result = thisDate < startDate || thisDate > endDate;

-- hugh
 
yes, that's genious.
thank you so much. i just switched back to the old code, it doesn't do it anymore. so strange
a last question: the last date isn't available, can i add a +1 or do i have give time 23:59:59 or 00:00:01?
if you don't have the time, doesn't matter, can change endDate easily
Once again a great cheers
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top