input type=checkbox
can.view.bindings.can-value-checkbox
Cross bind a value to a checkbox.
<input type='checkbox' can-value='KEY' can-true-value='TRUEVALUE' can-false-value='FALSEVALUE'/>
Cross binds the checked property to a true or false value.
Parameters
-
KEY
{key}
A named value in the current scope.
-
TRUEVALUE
{String}
OptionalUsed to set the checked value of
KEY
. -
FALSEVALUE
{String}
OptionalUsed to set the unchecked value of
KEY
.
Use
Using can-true-value
An alternative true and false value can be specified by setting
can-true-value
andcan-false-value
attributes. This is used for setting up a "boolean" property that only has two possible valid values, whose values are modelled by the true/false checked property of a checkbox, as in the following example:In this case, the data passed in contains a 'sex' property which is either 'male' or 'female'. Specifying the string values for true and false in the attributes forces the data to two way bind using these string properties.