-
Notifications
You must be signed in to change notification settings - Fork 24
@Selected
troyji edited this page Aug 16, 2011
·
18 revisions
@Selected
enforces the constraint that a select box must be selected. The constraint validates somewhat by convention; if the selectedIndex
property of the select box is 0
, then the select box is assumed to be unselected because in most cases the “unselected” value is usually the very first option in the select box.
Syntax for @Selected
is:
@Selected([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. |
<select id = "mySelect"
name = "mySelect"
data-constraints = '@Selected'>
<option value = "0">Please select a fruit</option>
<option value = "1">Strawberry</option>
<option value = "2">Orange</option>
<option value = "3">Banana</option>
</select>
<select id = "mySelect"
name = "mySelect"
data-constraints = '@Selected(label="fruit",
message="You need to select a {label}",
groups=[FirstGroup, SecondGroup, ThirdGroup]'>
<option value = "0">Please select a fruit</option>
<option value = "1">Strawberry</option>
<option value = "2">Orange</option>
<option value = "3">Banana</option>
</select>