In KeystoneJS, I need to pass all values from 2 MongoDB date fields to daterangepicker JS function isInvalidDate
The query in the controller is:
view.query('booked', Booking.model.find()
.select('startDate endDate'))
.then(function (err, results, next) {
if (err) return next(err);
console.log(results);
next();
});
In the jade view = booked
returns:
{ _id: 58f71314a20fc062ee02f4df, startDate: 2017-04-18T21:00:00.000Z,
endDate: 2017-04-19T21:00:00.000Z },{ _id: 58f8768c0741e2118b1efe43,
startDate: 2017-04-23T21:00:00.000Z, endDate: 2017-04-25T21:00:00.000Z },{...
and the isInvalidDate
function in the js block works as expected with a test array:
"isInvalidDate": function (date) {
var formatted = date.format('MM/DD/YYYY');
return ["03/03/2018","03/04/2018"].indexOf(formatted) > -1;
},
However, when I try replacing the test array with booked
, I get TypeError: booked is undefined
. And if it worked, the booked
array would need to be converted to the format ["03/03/2018","03/04/2018"]
(filtering out labels, and the unexpected _id
field value). Feels like there is a simpler way to getting this to work
Any guidance on how to proceed, or better solutions to passing the list of dates to the JS function would be truly appreciated
via Sudo Testuser
No comments:
Post a Comment