Hello,
I posted a few days ago, a request for help to code maxDate on a datePicker.
I have 2 datePickers in which certain dates are disabled thanks to a database.
I'm also using code to make the date selected in DatePicker1 the minimum date that can be selected in DatePicker2.
I now want to use maxDate so that the maximum date selectable in DatePicker2 is the first disabledDates after the date selected in datePicker1.
Following the answer that I was very kindly given, I use the code below:
import wixData from 'wix-data';
wixData.query ("News")
. eq ("dispo", true )
. limit (1000)
. find ()
. then ((res) => {
let items = res.items ;
if (items.length > 0) {
let disabledDates = [ ] ;
items.forEach (e => {
disabledDates.push (e.date) ;
} )
$w ("#datePicker1").disabledDates = disabledDates
$w ("#datePicker2").disabledDates = disabledDates
}
});
export function datePicker1_change() { console.log
let firstTime = new Date($w('#datePicker1').value).getTime();console.log
let timeTwoDaysHence = firstTime + (3 * 86400000);console.log
let dateTwoDaysHence = new Date(timeTwoDaysHence);console.log
$w('#datePicker2').minDate = dateTwoDaysHence;console.log
const disabledDates = $w('#datePicker2').disabledDateRanges.map(e => new Date (e.startDate).getTime());console.log
$w('#datePicker2').maxDate = new Date(disabledDates.find(e => firstTime < e));console.log
}
But maxDate does not work, and I get the following error:
TypeError: Cannot read properties of undefined (reading 'map')
Am I forgetting something?
I tried multiple solutions, but nothing works...
Thank you for your help.
Several places in your code you have console.log, but without any parameters. See this article on using console.log.
Also, it's really difficult reading your code. It would greatly help if you could format it nicely and post in a code block:
Thank you.