A checkbox in a WordPress web form is an input element that allows users to select one or more options from a set of choices. Checkboxes are commonly used when multiple selections are permitted. Checkboxes should not be confused with radio fields which only allow one selection to be chosen.
There are various ways of making Checkboxes required in WS Form.
Demo
Setting Individual Checkboxes As Required
To set set an individual checkbox as required:
- Click the Settings icon on the checkbox field.
- Click the Checkboxes tab.
- Click the Required icon in the data grid on the row(s) you want to be required.
- Click Save & Close at the bottom of the sidebar.
- Click Publish if you want to make the changes live.
Setting a Minimum or Maximum Checked Count
It is possible to choose a minimum or maximum number of checkboxes that must be checked in order to validate the field.
To do this:
- Click the Settings icon on the checkbox field.
- Click the Advanced tab.
- Scroll down to the Restrictions settings.
- Set the Minimum Checked and/or Maximum Checked setting.
Inline Validation
By default, Required, Minimum Checked and Maximum Checked settings are validated when the form is submitted.
You can also show if a checkbox is validated:
- Always
- On field change / blur
To do this:
- Click the Settings icon on the checkbox field.
- Click the Advanced tab.
- Scroll down to the Validation settings.
- In the Inline Validation setting:
- Choose Always to always show invalid feedback when a field is invalidated.
- Choose On Field Change or Blur to show invalid feedback when a field is changed or blurred (loses focus).
Conditional Logic
For more advanced applications, you can also check if a checkbox has been checked by using conditional logic. A simple example of this is shown below.
In this example, a checkbox row is monitored to see if it is not checked. If it is not checked, custom validity is set on the field which sets the invalid feedback shown to the user. If the checkbox is checked, the custom validity is set to blank which essentially removes the invalidity on the checkbox.