I'm developing a Google Calendar add-on to list all events from selected calendars. Now I can get the calendar list of current user but I don't know how to generate a group of checkboxes of them.
var calendar = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.CHECK_BOX)
.setTitle("Please choose the calendars.")
.setFieldName("calendar")
.addItem("common calendar", "commonCalendar",false)
.addItem("sales department calendar","salesDepartmentCalendar", false)
.addItem("development department calendar", "developmentDepartmentCalendar",false)
If you are looking for a way to add checkboxes for each calendar in your calendar list,
You can try this sample code:
var card = CardService.newCardBuilder()
.setName("Card name")
.setHeader(CardService.newCardHeader().setTitle("Card title"));
var widget = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.CHECK_BOX)
.setTitle("Please choose the calendars.")
.setFieldName("calendar");
var calendarList = CalendarApp.getAllCalendars();
Logger.log("Calendar Count:" + calendarList.length);
//Add checkbox per calendar
for (var i = 0; i < calendarList.length; i++) {
var calendar = calendarList[i];
Logger.log("calendar"+i);
//Add Calendar as Item
widget.addItem(calendar.getName(), "calendar"+i,false)
}
var cardSection = CardService.newCardSection().setHeader("Section header").addWidget(widget);
return card.addSection(cardSection).build();
Procedure:
value
parameter based on the calendar loop index (calendar0, calendar1, .... )Sample Output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.