input type=checkbox

  • function
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

  1. KEY {key}

    A named value in the current scope.

  2. TRUEVALUE {String}Optional

    Used to set the checked value of KEY.

  3. FALSEVALUE {String}Optional

    Used 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 and can-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:

<input type='checkbox' can-value='sex' can-true-value='male' can-false-value='female'/>

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.