Hi, I’m trying to extract a date type column form by DB and disable these dates on a Date Picker.
Apparently having issued on my FOR Loop because it won’t go through the code after the loop. I appreciate your help.
$w.onReady( function () {
$w(“#dataset1”).onReady( () => {
$w(“#dataset1”).getItems(0, 5)
.then( (result) => {
let items = result.items;
let fechasOcupadas = [];
for ( var i = 0; i < 5; i++) {
fechasOcupadas.push({“label”: items[i].fechaYHora.toDateString()});
}
$w(“#datePicker1”).disabledDates = fechasOcupadas;
})
. catch ( (err) => {
});
});
});
@amonsalvek Just a slight adjustment, and you’re there. No need to create an object and assign a string date value to a label. The disabledDates property expects an array of dates. So your “push” statement would be
fechasOcupadas.push(items[i].fechaYHora);
Hi anthony. Thanks for your response.
For some reasone I’m having two problems:
1st the code isn’t reading beyond the FOR Loop (even tried console.log and it won’t go through it)
2nd I changed the code to the one you said, and I also put the disableDates inside the Loop, but it shows the following error:
“Wix code SDK error: The disableDate parameter of item at index 0 that is passed to the disabledDates method cannot be set to the value [object Object]. It must be of type date.”
@amonsalvek I’ve tested the following code, and it disables certain dates in a datePicker element without errors:
$w.onReady(function () {
$w("#dataset1").onReady( () => {
$w("#dataset1").getItems(0, 5)
.then( (result) => {
let items = result.items;
let fechasOcupadas = [];
for (var i = 0; i < 5; i++) {
fechasOcupadas.push(items[i].fechaYHora);
}
$w("#datePicker1").disabledDates = fechasOcupadas;
})
.catch( (err) => {
});
});
});
thank you so much! it worked!!