Is it possible to have a checkbox that can add and remove multiple values to a field

Hi Tiddlywikians,
I tried this workarround, but somehow it acts like if I put $filter instead of $subfilter to the listops, and removes all other values…

\define uncheckday()
<$action-listops $field="timeline.days" $tiddler="$:/plugins/courseorganizer/schedule" $subfilter="-[{!!title}]"/>
\end
\define checkday()
<$action-listops $field="timeline.days" $tiddler="$:/plugins/courseorganizer/schedule" $subfilter="+[{!!title}]"/>
\end

<$list filter="Montag Dienstag Mittwoch Donnerstag Freitag" >
<$checkbox tag={{!!title}} tiddler="$:/plugins/courseorganizer/schedule" uncheckactions=<<uncheckday>>  checkactions=<<checkday>> >  {{!!title}}</$checkbox> <br>
</$list>

Best wishes Jan

Thanks for providing complete code!

The plus symbol “+” doesn’t mean “plus” in TW filters! Mentally, I think of it more as a “funnel filter” like maybe > which funnels the prior input and does something to it. Remove the “+” and I think you will find it works more like you were expecting.

1 Like

Yeah! Thanks!
For those who like it: Just remove the + the - can stay in place.
Jan

Jan, I think you need the -

I did a little hack to your code

\define uncheckday() <$action-listops $field="timeline" $subfilter="-[<day>]"/>
\define checkday()   <$action-listops $field="timeline" $subfilter="[<day>]" />

\define add-remove-tag-field(targetTiddler)
<$tiddler tiddler={{{ [<__targetTiddler__>is[tiddler]then[$targetTiddler$]else[$(currentTiddler)$]] }}} >
<$list filter="Monday Tuesday Wednesday Thursday Friday" variable=day>
  <$checkbox 
    tag=<<day>>
	  uncheckactions=<<uncheckday>>  
	  checkactions=<<checkday>> 
  > 
	  <<day>>
	</$checkbox><br>
</$list>
</$tiddler>
\end

So if you call anywhere the macro like below

<<add-remove-tag-field "$:/plugins/courseorganizer/schedule">>

It will add/remove tag/field values to/from $:/plugins/courseorganizer/schedule

If you call macro from a tiddler like

<<add-remove-tag-field>>

It will act on the current tiddler

2 Likes

Hi Mohammad,
thanks for adding a more generalized solution! I think this is a very practical snippet. So practical that even the field and the possible values could be added to the macro.
best wishes Jan

1 Like