Add values to field by clicking checkboxes

Many tiddlers in my TiddlyWiki have a ‘related’ field. Part of my edit template looks like this:

<$list filter="[<currentTiddler>has[related]]">
  <div style="column-count: 4;">
    {{{ [get[related]enlist-input[]unique[]sort[]] }}}
  </div>
</$list>

This produces a four column list of values appearing in ‘related’ field of all tiddlers. I, then, populate the ‘related’ field of the current tiddler by entering values manually.

But I would like to be able to click checkboxes next to these values and see them appear in the related field. So, I tried the following:

<$list filter="[<currentTiddler>has[related]]">
  <$list filter="[get[related]enlist-input[]unique[]sort[]]" variable="rwords">
    <$checkbox field="related" checked=<<rwords>> unchecked="" default="">
    <<rwords>></$checkbox><br>
  </$list>
</$list>

This means if I check a box next to ‘King’, the ‘related’ field of the current tiddler is set to ‘King’.

But I want to add ‘King’ to the existing values in ‘related’ field. And remove ‘King’ if I uncheck the box.

How do I get that behavior?

Also, this code produces a long list of values. How do I get that into four columns like my current set-up?

Once you’ve unchecked everything, what will be the source of your choices? You need to have a master source of choices outside of your “related” field.

Checkbox wants to bind a checked/unchecked status to ONE term in a field. So you can’t put multiple terms into the same field. You could use fields in a status tiddler that shadows your main tiddler, allowing you to bind the checkbox.

Checkbox has 3 different action attributes. These can be used to perform additional actions. So you could use <$action-listops> to add items to the related field as you check items.

Exactly the thought that passed my mind as I was looking for solutions. But I am not able to see how.

Hello Deshmukh
Mohammad’s TW Scripts has an example tiddler
“Create Links on Click Sets Some Fields”
This is a simple example create a lists from tiddlers tagged with contact. Each item is clickable and on click these actions are performed:

  • The value of myfield is set to the title of clicked item
  • It is navigated to the clicked item

I think this may be similar to what you want.

Scot

Some coding fun: “check boxes” that add/subtract from same field

A post of my way of setting that up, with a follow-up reply of a more formal approach.

Either way, there’s some fun code to study.

@Charlie_Veniot Thanks! That is an interesting solution.

In the meantime, I have developed another approach using a Google Groups post. I am writing it as a separate reply.

OK. Here is the final version I am using:

<div style="column-count: 4; line-height: 2;">
  <$list filter="[get[related]enlist-input[]unique[]sort[]]" variable="rwords">
    <$button type="button" class="btn btn-warning btn-mini" >
      <$action-listops $field="related" $subfilter="[<rwords>]" />
      {{$:/core/images/new-button}}
    </$button>
    <$button type="button" class="btn btn-info btn-mini" >
      <$action-listops $field="related" $subfilter="-[<rwords>]" />
      {{$:/core/images/delete-button}}
    </$button>
    <$link to=<<rwords>> /><br>
  </$list>
</div>

The idea of the buttons is copy pasted from a google group post here.

1 Like