choice validator

Check if the number of checked boxes are less or more than a given number

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
(* denotes a required option)
NameHTML attributeTypeDescription
maxdata-fv-choice___max*NumberThe maximum number of check boxes required to be checked
messagedata-fv-choice___messageStringThe error message
min*data-fv-choice___min or minNumberThe minimum number of check boxes required to be checked
At least one of min and max option is required.
The validator also supports the select element if the multiple="multiple" attribute is set.

Naming convention

In order to get the correct submit data in the server side, you should pay attention on setting the name attribute of checkbox/select elements.
Server sidename attributeExample
PHPname[]<input type="checkbox" name="languages[]" />
<select name="editors[]" multiple="multiple">
Spring frameworkname<input type="checkbox" name="languages" />
<select name="editors" multiple="multiple">

Basic example

The following form asks a developer to choose 2-4 programming languages which he/she is good at:
choice validator

See also