Validating radio buttons and checkboxes
When validating radio buttons and checkboxes, it is sufficient to add the validator on a single element (ie one radio button/checkbox), and the validator will treat all the grouped elements as a single input control.
Radio buttons
Radio buttons are simple: all input elements with
type="radio" and corresponding values for the name
attribute are treated as members of the same group. By adding the
required validator to one of the elements in this
group, Validatious checks that one of the radio buttons are checked.
Checkbox
With checkboxes, there is no default connection between checkboxes that apply
to the same field. For this reason, they must be linked together through a
class name. By adding a class name prefixed with g_ (as in
"group") you can link checkboxes together with corresponding group names.
Example: core API
The following example uses the core API to require that on of the buttons are
selected, and that atleast three checkboxes are selected. Note that both the
v2.Field constructor, and the v2.$f() method (that
looks up a field) takes an id as argument. In the case of checkboxes and radio
buttons, this need only be the id of one of the elements in the group
- which one doesn't matter.