listIndex
Mode
Using the checkbox widget in index list mode requires the listIndex
attribute to specify the the property of a DataTiddler. This property contains 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 property is undefined.
The following table summarizes the possible combinations:
defined attributes | |||
---|---|---|---|
neither | property missing or list empty no default defined | property 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 |
The example below creates three checkboxes that each control a different value in a property of the ExampleData tiddler.
<$set name=indexName filter="[<currentTiddler>addsuffix[ Colors]]" >
<$checkbox tiddler="ExampleData" listIndex=<<indexName>> checked="green" unchecked="red" default="red"> Green or red?</$checkbox><br/>
<$checkbox tiddler="ExampleData" listIndex=<<indexName>> checked="yellow" unchecked="blue" default="blue"> Yellow or blue?</$checkbox><br/>
<$checkbox tiddler="ExampleData" listIndex=<<indexName>> checked="orange" unchecked="purple" default="purple"> Orange or purple?</$checkbox><br/>
Colors list: <$text text={{{ [[ExampleData]getindex<indexName>] }}} />
</$set>
That renders as:
Colors list: