Enforce a maximum number of checkboxes selected in Form Assembly
I was creating a form for a client and we wanted to enforce a maximum number of checkboxes (tickboxes) to be selected in a multiple choice checkbox question.
The solution was a bit fiddly so we thought I’d post it here for future reference. The Form Assembly help page on this contains a good video but I wanted a super quick reference to how to do this in future so created this step by step blog:
Create your checkbox question.
There is no easy Form Assembly functionality to simply tick ‘maximum 4 to be selected’ or something like that so proceed to the next steps.
Make your checkbox question a variable and set a number of 1 for each of the options. When you give your Form Assembly variable a name, remember that you can only use letters and that the name is case sensitive – this is a little annoying to be honest (e.g. a prefix of Q5 has to be QFive) but once you know about this nuance, think about how your naming convention can work.
Create a text field which will be hidden and in the default value write your error message – we’ll essentially call upon this error message in later steps. Your settings will look something like this:
Create a new text field. Mark it as a calculated field with a formula something like the following – this formula is saying, if the maximum selected checkboxes is greater than 4, then show the error message, otherwise show nothing (this is the colon quote quote end of the formula).
Set up the Validation rules for this text field so that they can’t submit the form if they’ve selected too many check boxes. Change the expected input format to custom and paste in the regular expression below into the ‘Validate with a Regular Expression’ box:
According to the help video, you can add a Custom Error message for the field here too – although that didn’t work in my example, let me know if it does in yours and if you did something different from the help video.
Also, under Presentation Options, select Remove Label (no space) – note: when you do this your field will look like it’s disappeared even in non-preview mode, so don’t forget it’s there and you need it.
Check your question is working in the Preview screen.