amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.02k forks source link

Disable Dates with a variable #1194

Open astracrazy opened 4 years ago

astracrazy commented 4 years ago

Hello

I hope you can help. I am trying to disable dates from a variable which is generated from a AJAX request. The result of the request is the dates which I am trying to disable. I have then removed the double quotes which I think should not be there:

var formattedDisabledDates = JSON.stringify(data_disable_dates.dates); var formattedDisabledDates = formattedDisabledDates.replace(/['"]+/g, '');

The output in console log for formattedDisabledDates is as follows: [[2019,12,25],[2019,12,26],[2020,01,01],[2020,04,10],[2020,04,13],[2020,05,08],[2020,05,25],[2020,08,31],[2020,12,25],[2020,12,26],[2020,12,27],[2020,12,28],[2021,01,01]]

If i paste that into here: pickerPU.set('disable', #here#); it works fine and all the dates are disabled correctly.

If I replace it with the variable: pickerPU.set('disable', formattedDisabledDates);

I get an error back: Uncaught TypeError: datesToDisable.map is not a function this is from the picker.date.js file

The only way I can get in to work is using eval(formattedDisabledDates) but this is considered unsafe?

What am I doing wrong, can anyone help?

DanielRuf commented 4 years ago

Hi @astracrazy,

can you provide a reproducible testcase as codepen for us so we can take a look at this?