Dynamic selection options in Google Apps Script for forms

怎甘沉沦 提交于 2019-11-28 00:28:21

As far as I know, this type of client side event does not exist in Google Forms. The scripting mechanisms of Google Apps Script are designed for creating forms and other documents, but do not reach very far for client-side functionality.

What I suggest is that you split the form into multiple pages and use the "Go to page based on answer" feature to achieve your desired functionality.

Use form.addPageBreakItem() to create pages and use the item.createChoice(value, PageBreakItem) to navigate to the correct page.

References:

Google Apps Script Forms Service

addPageBreakItem

createChoice

Mogsdad

Edit: Thanks to the additional information in follow up comments, the question has been clarified, and boils down to this: "As a user makes selections in a Google Form, is it possible to customize the options in other questions on that form?"

A: No. See Dynamically edit multiple choice options in live Google Form using Apps Script.

Original Answer - this explains how one could change the options presented in a form when the source of those options (a spreadsheet) was edited.

If your data is in a Google Spreadhsheet, an onEdit or onChange trigger in the source spreadsheet would be able to respond to changes in the name and grade lists.

The onChange trigger is "installable", and is able to perform actions that a simple onEdit can't, such as modify a form, so it would be the better choice in this case.

In the trigger function, use FormsApp.openById() or FormsApp.openByUrl(), then update the previous item choices with item.setChoices(), reading the values from the spreadsheet just as you did when creating the form.

For bonus marks... instead of blindly overwriting the choices, you could read the existing choices and update them only if changed.

Caveat - on a sheet that changes frequently, or with long lists, this trigger will be computationally expensive. You may find that you run into Google's processing limits.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!