Disable dates in the datepicker based on values from the Google Sheet using Google Apps Script

后端 未结 1 1097
梦如初夏
梦如初夏 2021-01-22 02:08

From the html I made with date picker, if a date was selected and submitted, it\'s output will be saved in the Google Sheet.

Here is the sample output:

相关标签:
1条回答
  • 2021-01-22 02:48
    • You want to disable the dates of weekends and the dates retrieved from the values of Spreadsheet for the datepicker.
      • In your sample Spreadsheet, you want to disable August 20, 2019, July 26, 2019, July 19, 2019 and the weekends.

    If my understanding is correct, how about this modification? Please think of this as just one of several answers.

    Modified script:

    Please modify the function of populateDates() of HTML & Javascript side as follows.

    function populateDates(disabledDays){
      var dateSelect = document.getElementById('subDate');
      M.Datepicker.init(dateSelect, {
        minDate: new Date ("2019, 5, 10"), 
        maxDate: new Date ("2019, 8, 21"), 
        disableWeekends: true,
        disableDayFn: function(day){ // Modified
          return disabledDays.some(e => {
            var obj = new Date(e);
            return obj.getFullYear() == day.getFullYear() && obj.getMonth() == day.getMonth() && obj.getDate() == day.getDate();
          });
        }
      });
    }
    

    Note:

    • In this case, the values of disabledDays from revealDates() of Google Apps Script are the string values. So the string values are converted to the date object at the script of disabledDays = disabledDays.map(e => new Date(e)).
    • In this modification, I didn't modify Google Apps Script.

    Reference:

    • some()
    0 讨论(0)
提交回复
热议问题