Google Apps Script生成Google表单:多选项子版块跳转问题求助
解决Google Apps Script表单版块跳转问题
问题出在你对表单跳转逻辑的理解上:页面分隔符(PageBreakItem)本身不支持设置跳转,表单的导航规则是绑定在**问题(FormItem)**上的——用户提交某个问题的答案后,才会执行对应的跳转动作。你之前尝试给sectionOne(页面分隔符)调用setGoToPage,自然不会生效。
正确的做法是:给每个子版块的最后一个问题设置跳转,让用户回答完该问题后直接跳转到指定的nextPage。
修改后的完整代码
// 先创建目标跳转页,确保后续可引用 var nextPage = form.addPageBreakItem() .setTitle("The next page") .setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci"); // 设置多选问题 let mci = form.addMultipleChoiceItem() .setTitle("Question") .setRequired(true) // 设置第一版块 var sectionOne = form.addPageBreakItem() .setTitle("First Section") .setHelpText("This is the first section"); // 给版块最后一个问题添加跳转 form.addTextItem() .setTitle("Question inside section one") .setRequired(true) .setGoToPage(nextPage); // 关键:回答后跳转到nextPage // 设置第二版块 var sectionTwo = form.addPageBreakItem() .setTitle("Second section") .setHelpText("This is the second section"); form.addTextItem() .setTitle("Question inside section two") .setRequired(true) .setGoToPage(nextPage); // 关键:添加跳转 // 设置第三版块 var sectionThree = form.addPageBreakItem() .setTitle("Third section") .setHelpText("This is the third section"); form.addTextItem() .setTitle("Question inside section three") .setRequired(true) .setGoToPage(nextPage); // 关键:添加跳转 // 关联多选答案与对应版块 mci.setChoices([ mci.createChoice("first answer", sectionOne), mci.createChoice("second answer", sectionTwo), mci.createChoice("third answer", sectionThree) ]);
核心修改点
- 调整nextPage的创建顺序:先创建
nextPage,确保后续给问题设置跳转时能正确引用这个页面 - 给每个版块的最后一个问题绑定跳转:调用
setGoToPage(nextPage),让用户回答完该问题后直接跳转到目标页,不会继续走默认的表单流程进入其他版块
这样设置后,用户选择任一选项进入对应版块,完成版块内的问题后会直接跳转到nextPage,不会再进入其他子版块。
内容的提问来源于stack exchange,提问作者ElPaul0
相关产品推荐
相关产品推荐

