Google forms: Assign questions to Page Break and g

2019-09-08 02:26发布

With regard to this post, when more questions are added, to the same or different page, only the last question is correctly displayed. The other questions just show the structure (e.g. multiple choices, lists). The following code shows the problem:

function createForm() {
var title = 'Multipage Form Test';
var description = 'Stackoverflow question 17083500';

var form = FormApp.create('Questionnaire')
  .setDescription('Questionnaire')
  .setConfirmationMessage('Thanks for responding!');

var page1 = form.addPageBreakItem()
  .setTitle('First page');
var item = form.addMultipleChoiceItem();
var item = form.addListItem();
var item = form.addMultipleChoiceItem();
var page2 = form.addPageBreakItem()
  .setTitle('Second page');
var item = form.addMultipleChoiceItem();
var page3 = form.addPageBreakItem()
  .setTitle('Third page');

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes',page2),
     item.createChoice('No',page3)
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

Logger.log(form.getEditUrl());
Logger.log(form.getPublishedUrl());
}

How is it possible to assign and display the questions to pages correctly?

Thanks a lot for your answer, sofia p.

1条回答
混吃等死
2楼-- · 2019-09-08 02:55

Just needed to set the item choices immediately after adding each new item to the current page. All the choices were set / reassigned on just 1 item, after creating page 3.

var item = form.addMultipleChoiceItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

var item = form.addListItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes',page2),
     item.createChoice('No',page3)
   ]);

var item = form.addMultipleChoiceItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);
查看更多
登录 后发表回答