There may be times when it is useful to limit the number a checkboxes a respondent can check. Maybe you want to have 10 possibilities in a checkbox field, but you only want respondents to check a maximum of 5.
Please Note: This use case uses custom code which our Support Team is unable to assist in writing or editing. You can reach out to our team about the code referenced in this documentation. However, any editing or changes in the code will not be supported if issues occur.
Prepare Your Form
- Create your checkbox field in your form.
- Label and add choices to your checkbox field.
- Select your checkbox field and click Options > Calculations > This is a variable.
- Choose a name for the variable. For this example, we'll use "total".
- Assign a value of "1" for each option.
- Add a Text Input Field to your form. Give it any label. For this example, the label is "Error".
- Select the Text Input Field and click Options > Default Value and set the value for this field to "You may only choose 2 options".
- Next, scroll down in the Options menu for the Error field and click Calculations > This is a variable.
- Choose a name for this variable. For this example, we chose "error".
- Scroll down in the Options menu for the Error field and set the Access Control to "Hidden".
- Add a new Text Input Field to your form. Give it any label. For this example, the label is "Checkbox Calculation".
- Select the Checkbox Calculation field and click Options > Presentation > Label Placement > Remove Label.
- Scroll down in the Options menu and click Calculations > This is a calculated field.
- Enter the following formula with your own variables:
- Scroll up in the Options menu and click Validation Rules > Expected Input Format > Custom.
- Under "Validate with a Regular Expression" enter the following:
- Your validation should look like this:
- Save your form.
- Test your new setup by clicking View and then testing in the live form.