Class CheckboxItem

核取方塊項目

這類問題項目可讓受訪者選取一或多個核取方塊,以及選填「其他」欄位。您可以透過 Form 存取或建立項目。在測驗中使用時,系統會自動評分。

// Open a form by ID and add a new checkbox item.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?')
    .setChoices([
      item.createChoice('Ketchup'),
      item.createChoice('Mustard'),
      item.createChoice('Relish'),
    ])
    .showOtherOption(true);

方法

方法傳回類型簡短說明
clearValidation()CheckboxItem移除這個核取方塊項目的所有資料驗證。
createChoice(value)Choice建立新選項。
createChoice(value, isCorrect)Choice建立新選項。
createResponse(responses)ItemResponse為這個核取方塊項目建立新的 ItemResponse
duplicate()CheckboxItem建立這個項目的副本,並附加到表單結尾。
getChoices()Choice[]取得項目的所有選項。
getFeedbackForCorrect()QuizFeedback|null傳回受訪者正確回答問題時顯示的回饋。
getFeedbackForIncorrect()QuizFeedback|null傳回作答者回答問題錯誤時顯示的意見回饋。
getHelpText()String取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。
getId()Integer取得項目的專屬 ID。
getIndex()Integer取得表單中所有項目中的項目索引。
getPoints()Integer傳回可評分項目的點數值。
getTitle()String取得項目的標題 (如果是 SectionHeaderItem,有時稱為標頭文字)。
getType()ItemType取得項目的類型,以 ItemType 表示。
hasOtherOption()Boolean判斷項目是否具有「其他」選項。
isRequired()Boolean決定受訪者是否必須回答問題。
setChoiceValues(values)CheckboxItem從字串陣列為項目設定選項。
setChoices(choices)CheckboxItem為項目設定選項陣列。
setFeedbackForCorrect(feedback)CheckboxItem設定作答者答對問題時顯示的回饋。
setFeedbackForIncorrect(feedback)CheckboxItem設定作答者答錯問題時顯示的意見回饋。
setHelpText(text)CheckboxItem設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。
setPoints(points)CheckboxItem設定可評分項目的分數。
setRequired(enabled)CheckboxItem設定受訪者是否必須回答問題。
setTitle(title)CheckboxItem設定項目的標題 (如果是 SectionHeaderItem,有時也稱為標題文字)。
setValidation(validation)CheckboxItem為這個核取方塊項目設定資料驗證。
showOtherOption(enabled)CheckboxItem設定項目是否具有「其他」選項。

內容詳盡的說明文件

clearValidation()

移除這個核取方塊項目的所有資料驗證。

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

createChoice(value)

建立新選項。

參數

名稱類型說明
valueString選項的值,受訪者查看表單時會看到這個標籤

回攻員

Choice:新選擇

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

createChoice(value, isCorrect)

建立新選項。

參數

名稱類型說明
valueString選項的值,受訪者查看表單時會看到這個標籤
isCorrectBoolean選項是否為正確答案

回攻員

Choice:新選擇

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

createResponse(responses)

為這個核取方塊項目建立新的 ItemResponse。引數 responses 是包含需要檢查值的 String[] 陣列。如果任何值不符合這個項目的有效選項,系統就會擲回例外狀況,除非 showOtherOption(enabled) 設為 true

參數

名稱類型說明
responsesString[]這個選擇題項目的有效答案陣列

回攻員

ItemResponse - 項目回應

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

duplicate()

建立這個項目的副本,並附加到表單結尾。

回攻員

CheckboxItem:這個 CheckboxItem 的副本,用於串連

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getChoices()

取得項目的所有選項。

回攻員

Choice[]:選項陣列

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getFeedbackForCorrect()

傳回受訪者正確回答問題時顯示的回饋。

回攻員

QuizFeedback|null:意見回饋 (如有)。

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getFeedbackForIncorrect()

傳回作答者回答問題錯誤時顯示的意見回饋。

回攻員

QuizFeedback|null:意見回饋 (如有)。

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getHelpText()

取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。

回攻員

String:項目的說明文字

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getId()

取得項目的專屬 ID。

回攻員

Integer:商品的 ID

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getIndex()

取得表單中所有項目中的項目索引。

回攻員

Integer:項目的索引

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getPoints()

傳回可評分項目的點數值。

回攻員

Integer:問題的分數。

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getTitle()

取得項目的標題 (如果是 SectionHeaderItem,有時稱為標頭文字)。

回攻員

String:項目的標題或標頭文字

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getType()

取得項目的類型,以 ItemType 表示。

回攻員

ItemType:項目的類型

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

hasOtherOption()

判斷項目是否具有「其他」選項。

回攻員

Boolean - true (如果項目有「其他」選項);false (如果沒有)

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

isRequired()

決定受訪者是否必須回答問題。

回攻員

Boolean - 受訪者是否必須回答問題

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setChoiceValues(values)

從字串陣列為項目設定選項。如果指定陣列為空白,就會擲回例外狀況。

// Open a form by ID and add a new list item.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?');
item.setChoiceValues(['Dogs', 'Cats']);

參數

名稱類型說明
valuesString[]選項值陣列,受訪者查看表單時會看到這些值做為標籤

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setChoices(choices)

為項目設定選項陣列。如果指定陣列為空值或包含 null 元素,就會擲回例外狀況。

// Open a form by ID and add a new list item.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?');
item.setChoices([item.createChoice('Cats'), item.createChoice('Dogs')]);

參數

名稱類型說明
choicesChoice[]選項陣列

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

擲回

Error:如果指定陣列為 null、空白或包含 null 元素

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setFeedbackForCorrect(feedback)

設定作答者答對問題時顯示的回饋。

// Open a form by ID and add a new list item.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?');
// Set "Dogs" as the correct answer to this question.
item.setChoices([
  item.createChoice('Dogs', true),
  item.createChoice('Cats', false),
]);
// Add feedback which will be shown for correct responses; ie "Dogs".
item.setFeedbackForCorrect(
    FormApp.createFeedback().setDisplayText('Dogs rule, cats drool.').build(),
);

參數

名稱類型說明
feedbackQuizFeedback新意見回饋。空值會清除意見回饋。

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setFeedbackForIncorrect(feedback)

設定作答者答錯問題時顯示的意見回饋。

參數

名稱類型說明
feedbackQuizFeedback新的意見回饋

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setHelpText(text)

設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItemsPageBreakItemsSectionHeaderItems)。

參數

名稱類型說明
textString新的說明文字

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setPoints(points)

設定可評分項目的分數。新項目的預設值為 0。

參數

名稱類型說明
pointsInteger問題項目的分數

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setRequired(enabled)

設定受訪者是否必須回答問題。

參數

名稱類型說明
enabledBoolean受訪者是否必須回答問題

回攻員

CheckboxItem - 目前項目 (用於鏈結)

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setTitle(title)

設定項目的標題 (如果是 SectionHeaderItem,有時也稱為標題文字)。

參數

名稱類型說明
titleString新標題或標頭文字

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setValidation(validation)

為這個核取方塊項目設定資料驗證。傳遞空值或沒有任何呼叫 require 函式的驗證,會移除先前的驗證。

參數

名稱類型說明
validationCheckboxValidation要套用至此項目的 CheckboxValidation。

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

showOtherOption(enabled)

設定項目是否具有「其他」選項。新 CheckboxItemMultipleChoiceItem 的預設值為 false

參數

名稱類型說明
enabledBoolean如果項目有「其他」選項,則為 true;否則為 false

回攻員

CheckboxItem - this CheckboxItem,用於鏈結

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms