Search code examples
google-apps-scriptdatepickertimepickergoogle-workspace-add-ons

How to clear content in timepicker instantly after I changed datepicker?


I'm working on a Google calendar add-on with a datepicker and timepicker using CardService. And here's the code.

var startDate = CardService.newDatePicker()
  .setTitle("Start Date:")
  .setFieldName("startDate")

var startTime= CardService.newTimePicker()
  .setTitle("Start Time:")
  .setFieldName("startTime")
  .setHours(10)
  .setMinutes(0)

I want the timepicker to change instanly after I change the datepicker. To be more precise, I want the timepicker to be cleared and show as blank when I set the datepicker as today, while show 10:00 AM when I set it as other days.

I was thinking set no default time of the timepicker and change it when I set the datepicker other than today, but at the first place it shows 12:00 AM instead of blank. So it seems that this way doesn't work.


Solution

  • The time picker will always have a value (it can't be blank). If you don't set your own default value by adding hours and minutes, the default will be 00:00 hrs or 12:00 am as it is the start of the day.