Disable the days of week in a datepicker

Hi!
I have a database collection where my users save his days of availability.
The main fields are boolean type, and my users choose the day.
Example:
Monday:
Tuesday:
Wednesday:
Thursday: Yes
Friday: Yes
Saturday: Yes
Sunday: Yes

Then I want to use the API disabledDaysOfWeek to automatically disable the days in a datepicker in my page.

About the example, How to disable Monday, Tuesday and Wednesday in a datepicker.
I can´t fill the array [ ] programatically,

Can you help me please!!

have you tried:

$w("#myDatePicker").disabledDaysOfWeek = [1, 2, 3];

If I understood correctly, you need to transform your boolean fields to an array that fits the user choices and then set the disabledDaysOfWeek with the created array.
Please tell if you need help with the array creation :slight_smile:

Hi Eli, thanks for answer.
The code is:

$w(“#dynamicDataset”).onReady( () => {
let itemObj = $w(“#dynamicDataset”).getCurrentItem(); // read the collection
let valor = “”;
if( !itemObj.monday ) { value = value + 1 + ‘,’ ; } // disable Monday
console.log(value);
if( !itemObj.tuesday ) { value = value + 2 + ‘,’ ; } // disable Tuesday
console.log(value);
if( !itemObj.Wednesday ) { value = value + 3 + ‘,’ ; } // disable Wednesday
console.log(value);
if( !itemObj.Thursday ) { value = value + 4 + ‘,’ ; } // disable Thursday
console.log(value);
if( !itemObj.Friday ) { value = value + 5 + ‘,’ ; } // disable Friday
console.log(value);
if( !itemObj.saturday ) { value = value + 6 + ‘,’ ; } // disable Saturday
console.log(value);
if( !itemObj.sunday ) { value = value + 0 + ‘,’ ; } // disable Sunday
console.log(value);

 $w("#datePicker1").disabledDaysOfWeek = [value]; 

} );

But always show “,” at the end of the value.
Example:
$w(" #myDatePicker ").disabledDaysOfWeek = [1, 2, 3, ];

How do i delete the last “,”?

well,
I’d suggest another way to store the days values. I think it’s better to use an array in while you build it and then set it to ‘disabledDaysOfWeek’ property
Try something like this:


$w("#dynamicDataset").onReady( () => {
   let itemObj = $w("#dynamicDataset").getCurrentItem(); // read the collection
   let disabledDaysOfWeekArr = [];
    if( !itemObj.monday ) { disabledDaysOfWeekArr.push[1]; } // disable Monday 
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.tuesday ) { disabledDaysOfWeekArr.push[2]; } // disable Tuesday 
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.Wednesday ) { disabledDaysOfWeekArr.push[3]; } // disable Wednesday
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.Thursday ) { disabledDaysOfWeekArr.push[4]; } // disable Thursday
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.Friday ) { disabledDaysOfWeekArr.push[5]; } // disable Friday
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.saturday ) { disabledDaysOfWeekArr.push[6]; } // disable Saturday
    console.log(disabledDaysOfWeekArr);
    if( !itemObj.sunday ) { disabledDaysOfWeekArr.push[7]; } // disable Sunday
    console.log(disabledDaysOfWeekArr);
    $w("#datePicker1").disabledDaysOfWeek = disabledDaysOfWeekArr;
} );

thanks a lot Eli!

Hi Eli,

I tried to implement this for a dynamic page. But it didn’t work.

Would you be able to advise what is the best way to disable days from a database? Thanks.