Checkbox to populate field

Dear friends,

I have this button

<$button class="tc-btn-invisible tc-tiddlylink">
<$action-listops $field=laws  $filter="[enlist{!!laws}][contains:Reg0-axis1[ΕΠΔΔ]]"/>
ΕΠΔΔ
</$button><$button>
<$action-listops $field=laws  $filter="[enlist{!!laws}]-[contains:Reg0-axis1[ΕΠΔΔ]]"/>
Χ
</$button>

Is it possible to have the same functionality with a checbox?

Thanks in advance!

Give this a try:

\procedure addlaws(id)
<$action-listops $field=laws $filter="[enlist{!!laws}][contains:Reg0-axis1<id>]"/>
\end

\procedure removelaws(id)
<$action-listops $field=laws $filter="[enlist{!!laws}]-[contains:Reg0-axis1<id>]"/>
\end

<$checkbox field="ΕΠΔΔ" checked="yes" unchecked="no" default="no"
   checkactions="<<addlaws ΕΠΔΔ>>" uncheckactions="<<removelaws ΕΠΔΔ>>">ΕΠΔΔ</$checkbox>

LAWS={{!!laws}}

Note that the $checkbox widget has a separate field (e.g., field="ΕΠΔΔ") to track the current checkbox state (yes or no), and the addlaws() and removelaws() procedures are used to update the laws field contents as a “side-effect” of toggling that checkbox state.

enjoy,
-e

1 Like

Hello Eric, thank you very much, this works great!
May I trouble you for a new problem: lets say I have two or more checkboxes like that.

when I check the first one I get the results A, B, C

When I check the second one (so they’ re both checked) I get A,B,C,D, E

as expected: the two filters have C in common, so when the both apply we get C an also D, E (which meet the criteria of the second checkbox only).

Now lets say I uncheck the first checkbox: I would need to see C, E, D (which are the results of the second filter). But I only get D, E

The common result doesnt show up, even if I close and open or edit the tiddler.

The only thing that works is to unchek and recheck the second checkbox. Then I get the expected

So I guess I need some code to automate that. I tried removing contains: from the uncheck procedure but i still get wrong results (my actual case has 2-3 common results between 2-3 filters).

I suppose one way would be to modify the second procedure to delete all relevant fields, thus resetting the checkboxes so the user would start over, but it is counter intuitive (also I don’t know how to do that either :slight_smile:)

any help would be appreciated and thank you (all) for your time!

Minor update: please never mind that:

I suppose one way would be to modify the second procedure to delete all relevant fields, thus resetting the checkboxes so the user would start over, but it is counter intuitive (also I don’t know how to do that either.

Also I’ve set up a minimal test case here https://mtc.tiddlyhost.com/ to make tinkering a bit easier!

thank you!

Thanks for the minimal test case… it does make “tinkering” MUCH easier!

Try this:

\procedure setlaws()
<$set name=taxation       filter="[contains:Reg0-axis1[taxation]]">
<$set name=administration filter="[contains:Reg0-axis1[administration]]">
<$set name=laws filter="
   [{!!taxation}match[yes]then<taxation>enlist-input[]]
   [{!!administration}match[yes]then<administration>enlist-input[]]
">
<$action-setfield laws=<<laws>>/>
\end

<$checkbox field="taxation" checked="yes" unchecked="no" default="no"
   actions="<<setlaws>>"> taxation</$checkbox>

<$checkbox field="administration" checked="yes" unchecked="no" default="no"
   actions="<<setlaws>>"> administration</$checkbox>

LAWS={{!!laws}}

Notes:

  • Instead of checkactions="<<addlaws>>" and uncheckactions="<<removelaws>>", we now use a single actions="<<setlaws>>" procedure that is called whenever a checkbox state changes, regardless of whether it is checked or unchecked.
  • The setlaws() procedure first collects lists of tiddlers for each law category (e.g., taxation and administration).
  • Next, it combines these lists, but only when the corresponding checkbox is “yes”. Note that any tiddlers that occur in both lists (e.g., tiddler “C”) will only occur once in the combined list, since filter syntax uses dominant append logic by default.
  • Then, it sets the laws field to the resulting combined list.

enjoy,
-e

Dear Eric,

it works great, thank you very much!

TS

PS: Bear in my mind, I am not a native speaker, so please excuse any silliness! :slight_smile: