Editor - set a date range relative to today
Editor - set a date range relative to today

Hello, in the following a sample of my code
fields: [
...
{
"label": "DATE:",
"name": "date",
"type": "datetime",
"format": "ddd, D MMM YY",
opts: {
disableDays: [ 0, 6 ],
minDate: new Date('2017-01-18'),
maxDate: new Date('2017-01-23')
}
},
I would like to have "today" as minDate and ("today" +4 working days) as maxDate, taking also into account that Saturday and Sunday have been disabled (this means that if "today" is Thursday, ("today" +4 working days) should be Wednesday.
Any suggestion?
Many thanks in advance
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Basically do as you have done using
new Date()
but add 4 days to it:Allan
Thank, Allan, it works fine!
Any suggestion how to simply exclude the 'disableDays' from the counting?
No - I'm afraid that would need to be taken into the calculation. I suspect Moment will have a way of adding only working days.
Allan
Hi, I solved using pure JavaScript in this way
Just one last question. I noticed that in order to be able to choose "today" on the datepicker I need to set the "startDate" the day before, or in other words
There is a specific reason or I am doing something wrong?
Thanks
Very nice - thanks for sharing your code with us!
That's basically an artefact of the way the dates are being set to exactly midnight for each date in the calendar, and that you are passing in a date / time that is not midnight. If you set the time of your date object to be exactly midnight, it should work as expected.
Allan