How do I make checkboxes required?

Checkboxes cannot be managed by the FORM_FIELDS_REQUIRED control in WorkflowGen, since by definition a checkbox is optional.

If you need to have one or more checkboxes on your webform that must be selected (required) before the user can submit the form, you can validate this rule by using the JavaScript below, which can be added to a CustomFieldValidator in your webform. This CustomFieldValidator would use the WFGENPage ValidationGroup as its reference and call the validation JavaScript (e.g. ClientValidationFunction=ValidateCheckBox).

The group of checkboxes must have an ID that share the same prefix
(e.g. REQUIRED_CHECKBOX_1, REQUIRED_CHECKBOX_2, etc.

  1. Edit the checkbox web form control(s):

    <asp:CheckBox ID=REQUIRED_CHECKBOX_1 runat=server Text=Option 1 /><asp:CheckBox ID=REQUIRED_CHECKBOX_2 runat=server Text=Option 2 />etc...
    
  2. Add a web form CustomFieldValidator:

    <asp:CustomValidator ID=cfv runat=server ErrorMessage=The checkbox group is required. Display=None Enabled=True SetFocusOnError=True ValidationGroup=WFGENPage ClientValidationFunction=ValidateCheckBox></asp:CustomValidator>
    
  3. Add a JavaScript:

    function ValidateCheckBox(source, arguments){ var ValidateResult = true; // call CheckAll to validate a specific checkbox group //(e.g.: REQUIRED_CHECKBOX_x where x is the unique part of the ID) ValidateResult = CheckAll(REQUIRED_CHECKBOX_); arguments.IsValid = ValidateResult; }function CheckAll(MyPrefix){ var retval = false; if (MyPrefix != ) { var elem = document.getElementById('form1').elements; // validate if one or more checkboxes are checked for (var i = 0; i < elem.length; i++) { if (elem[i].name.length >= MyPrefix.length) { if (elem[i].name.substring(0, MyPrefix.length) == MyPrefix) { if (document.getElementById(elem[i].name).checked == true) { retval = true; return retval; } } } } // make borders red if no checkboxes in the group are checked if (retval == false) { for (var i = 0; i < elem.length; i++) { if (elem[i].name.length >= MyPrefix.length) { if (elem[i].name.substring(0, MyPrefix.length) == MyPrefix) { document.getElementById(elem[i].name).style.backgroundColor = #FF0000; } } } } } return retval;}
    

You can use this sample as a starting point to create a parameter-based function that makes checkboxes required based on a comma-delimited list similar in concept to FORM_FIELDS_REQUIRED.