-
Notifications
You must be signed in to change notification settings - Fork 25
@Checked
vivin edited this page Jul 19, 2012
·
24 revisions
@Checked enforces the constraint that a radio button, radio-button group, or a checkbox must be checked. If the element in question is not checked, the constraint will fail.
Syntax for @Checked is:
@Checked([label=label-text] , [message=message-text] , [groups=array-of-group-names])| Name | Type | Required | Description |
|---|---|---|---|
label |
String | no | An optional parameter that specifies the label for this input element. Labels are a way to provide friendly names to input elements. If the constraint fails to validate, the value in this field will be used in the default error message. If the constraint has a custom error message which contains {labe}, the value of this parameter will be substituted in the place of {label}. |
message |
String | no | An optional parameter that specifies the error message to use when this constraint fails. The value for this field can contain interpolations of parameters used by the constraint . For example: {label} needs to be {param1}. |
groups |
Array | no | An array of group names that specifies the validation groups that this constraint belongs to. |
<input id = "myCheckbox"
name = "myCheckbox"
type = "checkbox"
data-constraints = '@Checked' /><input id = "myRadio0"
name = "myRadioGroup"
type = "radio"
data-constraints = '@Checked' /> One
<input id = "myRadio01
name = "myRadioGroup"
type = "radio"
data-constraints = '@Checked' /> Two
<input id = "myRadio2"
name = "myRadioGroup"
type = "radio"
data-constraints = '@Checked' /> ThreeNote: Strictly speaking, it is not necessary to bind
@Checked to each radio-button in a radio-button group; you can just bind it to one. If validation fails, you will get back one constraint-violation and the failingElements attribute of that constraint violation will contain all radio-button elements of the radio-button group.
<input id = "myCheckbox"
name = "myCheckbox"
type = "checkbox"
data-constraints = '@Checked(label="The fantastic checkbox",
message="{label} needs to be checked",
groups=[FirstGroup, SecondGroup, ThirdGroup]' />