listField
Mode
Using the checkbox widget in list mode requires the listField
attribute to specify the name of a field containing a list. The checked
attribute specifies the value that should be present or absent in the list when the checkbox is checked or unchecked respectively. If checked
is absent (or empty) but unchecked
is present, then the logic will be inverted: the checkbox will be checked when the unchecked
value is missing from the list, and unchecked when the unchecked
value is found in the list. If both checked
and unchecked
are present, the checkbox will work like a toggle, replacing the checked
value with the unchecked
value and vice-versa. Finally, if neither checked
nor unchecked
is specified, the checkbox will be checked if the field has anything in it, but unchecked if the field is missing or empty. (This is rarely useful. Most of the time you want to specify checked
or unchecked
or both.)
The default
attribute is used as a fallback for the checkbox state if the field is not defined.
The following table summarizes the possible combinations:
defined attributes | |||
---|---|---|---|
neither | field missing or list empty no default defined | field has any value | – |
checked =item1 | item1 removed from list | item1 added to list | – |
unchecked =item2 | item2 added to list | item2 removed from list | – |
both | item1 removed from listitem2 added to list | item1 added to listitem2 removed from list | item1 not in listitem2 not in listno default defined |
This example creates a checkbox that is checked if the list field named colors
contains green
and unchecked if the field contains red
. If the field is undefined, or if neither green
nor red
appears in the field, then it defaults to green
, meaning that the checkbox will be checked.
<$checkbox listField="colors" checked="green" unchecked="red" default="green"> Is "green" in colors?</$checkbox><br />''colors:'' {{!!colors}}
That renders as:
colors:
Try editing the colors
field of this tiddler to see how the example changes.