Class CheckboxValidation Stay organized with collections Save and categorize content based on your preferences.
Page Summary
CheckboxValidation is a DataValidation specifically for CheckboxItems in Google Forms.
It allows you to set requirements for the number of choices a user must select from a checkbox item.
You can customize the help text displayed to the user when the validation is not met.
The provided code example demonstrates how to create a CheckboxValidation that requires exactly two selections.
CheckboxValidation
A DataValidation for aCheckbox.
// Add a checkBox item to a form and require exactly two selections.constform=FormApp.create('My Form');constcheckBoxItem=form.addCheckboxItem();checkBoxItem.setTitle('What two condiments would you like on your hot dog?');checkBoxItem.setChoices([checkBoxItem.createChoice('Ketchup'),checkBoxItem.createChoice('Mustard'),checkBoxItem.createChoice('Relish'),]);constcheckBoxValidation=FormApp.createCheckboxValidation().setHelpText('Select two condiments.').requireSelectExactly(2).build();checkBoxItem.setValidation(checkBoxValidation);
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.