问题
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:
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')
]);
来源:https://stackoverflow.com/questions/21827488/google-forms-assign-questions-to-page-break-and-go-to-page