Multiple checkboxes in a tiddler that retain state

try making a global macro (a tiddler tagged with $:/tags/macro) with this:

\define id(num) $(currentTiddler)$-$num$

and then in your tiddler:

<$checkbox tiddler="ExampleData" 
index=<<id "1">> checked="selected" unchecked="" 
default=""> Selected?</$checkbox>

It’s basically the same thing, except we manually feed the number to the id macro.

Have a great day!

Also depending on the use case you can set the checkbox state to be stored in a field on the current or any tiddler, just choose a different fieldname for each. The selection then stays with the tiddler.

Q1=yes
Q2=no
Q3=yes

First, the checkbox state reflects some value stored somewhere. In you example, you’re setting a (data tiddler) index named as the current tiddler. If you set some other index in that same tiddler, then that should also work and be reflected in any checkbox that looks at that other index.

Thus when you say “But that means I can have only one checkbox in a tiddler.” it seems you refer to currentTiddler as the same tiddler each time. Instead, you can choose some other index. You can, for example, manually specify different indexes or you can include that whole checkbox construct in a listwidget so that currentTiddler is different for each loop.

BTW, I don’t think indexes in datatiddlers accept e.g capital letters. Not sure. For sure it will not accept any arbitrary characters (e.g :). You might consider having the checkbox set fields instead of indices.

Is there a way by which instead of passing an argument every time, some random string is used instead? It would be great if that random string is the current time in YYYY0MM0DD0hh0mm0ssxxx format. Then, we can have:

<$checkbox tiddler="ExampleData" 
index=<<theuniqueid>> checked="selected" 
unchecked="" default=""> Selected?</$checkbox>

And ExampleData tiddler would carry something like:

{
    "tidA20211005143612345": "",
    "tidA20211005143612346": "",
}

I tried

\define theuniqueid $(currentTiddler)(now "YYYY0MM0DD0hh0mm0ssxxx")$

But that did not work.

Oh man, this has me stumped :smile:. I have some ideas, but I need to get on my computer first.

To clarify: do you require the exact time when the checkbox was ticked?

@sull-vitsy Thanks. And I am really sorry if my questions are too naive.

I do not need the ‘exact’ time. I was using exact time to concatenate the tiddler name to avoid any chance of having the same index — I am unlikely to be able to add text or click that fast :slight_smile:

Plus, merely looking at the index, one can figure out from where and when it has come. So, for readability, it would be better to use “YYYY-0MM-0DD 0hh:0mm:0ss xxx” format for the now widget.

On a related note, will the index value change when I uncheck the box?

What actually are you trying to achieve in the end? It seems that the checkbox values you want to set are only to be used to reflect the state of the checkbox and that this checkbox is only to be seen in one place (because the only thing to identify the checkbox with would be via the random value you attempt to create), is that right?

Anyway, this:

…doesn’t work because it breaks several syntax rules. I’m not sure the following will work but it is at least a bit of an improvement:

\define theuniqueid() $(currentTiddler)$<<now "YYYY0MM0DD0hh0mm0ssxxx">>

Absolutely. That is what I want to achieve. I will take a minute of yours to tell you how I am planning to use it.

I have a tiddler called QuickTasks. I use it to capture several tasks that will take hardly any time to complete. But I do not want to do them now. These are transient in nature. But may crop up again after a few days. A good example is ‘Replace batteries’.

My workflow is:

QuickTasks contain:

\define theuniqueid() $(currentTiddler)$<<now "YYYY0MM0DD0hh0mm0ssxxx">>

<$checkbox tiddler="ExampleData" index=<<theuniqueid>> checked="done" unchecked="" default="">Replace Batteries</$checkbox><br>

I will just copy paste the checkbox line and edit the ‘Replace Batteries’ part. When I complete a task, I do not need to edit the tiddler. I just check that box and be done. Later on, when I have time, I will delete the lines I do not need from QuickTasks tiddler.

I know, as a workflow, it is clumsy. But this seems to work right now for me.

Hope I am clear. Please ask if something is unclear.

1 Like

And this did not produce the index we want. <<now “YYYY0MM0DD0hh0mm0ssxxx”>> appeared verbatim in the index value.

I know this isn’t related to your question, but there are some cool plugins for task management and quick tasks. See Todolist which is a simple todolist maker. You call a macro, you add tasks, you tick off checkboxes.

Projectify leans more towards project management, but it has a quick-add todo function. You just press alt+c from anywhere in your wiki and it’ll open an inbox tiddler where you can add tasks quickly.

I know, as a workflow, it is clumsy. But this seems to work right now for me.

I will have to agree with you :wink: …but maybe it is a good start until you want to improve upon it.

This should solve the evaluation problem:

\define theuniqueid() $(currentTiddler)$<<uid>>

<$vars uid=<<now "YYYY0MM0DD0hh0mm0ssXXX">> >
<$checkbox tiddler="ExampleData" index=<<theuniqueid>> checked="done" unchecked="" default="">Replace Batteries</$checkbox>
</$vars>
<br>

You can test if the following even works, i.e no separate macro:

<$checkbox tiddler="ExampleData" index=<<now "<<currentTiddler>>YYYY0MM0DD0hh0mm0ssXXX">> checked="done" unchecked="" default="">Replace Batteries</$checkbox>
<br>

@sull-vitsy It is very much related. For my use case, these plugins provide an out-of-box solutions. So, thanks for suggesting.

@twMat Thanks.

I, too, hope it will improve. In fact, solutions suggested by @sull-vitsy are way more elegant.

This does not work it creates an index value of QuickTasks<<uid>>.

<$checkbox tiddler="ExampleData" index=<<now "<<currentTiddler>>YYYY0MM0DD0hh0mm0ssXXX">> checked="done" unchecked="" default="">Replace Batteries</$checkbox>
<br>

This does not work, too. It creates index value of <<currentTiddler>>202110.....

OK, this works

\define uid() $(tid)$$(time)$

<$vars tid=<<currentTiddler>> time=<<now YYYY0MM0DD0hh0mm0ssXXX>>>
<$checkbox tiddler="ExampleData" index=<<uid>> checked="done" unchecked="" default=""> Replace Batteries</$checkbox>
</$vars><br>

You can put all of it in a macro and call it with only your “item”, e.g:

\define uid() $(tid)$$(time)$

\define aaa(item)
<$vars tid=<<currentTiddler>> time=<<now YYYY0MM0DD0hh0mm0ssXXX>>>
<$checkbox tiddler="ExampleData" index=<<uid>> checked="done" unchecked="" default=""> $item$</$checkbox>
</$vars>
\end

<<aaa "Replace batteries">>

@twMat Thank you so much. Yes. It does. The ExampleData tiddler does carry an index properly named.

But this also means that as soon as it is checked. the box gets unchecked. Time moves on. 20211006141516789 becomes 20211006141516790. So, the checkbox attached to ‘Replace Batteries’ now has a new value that is not in the index. So, it is set to default - unchecked. :slight_smile:

He he - right!

OK, so one idea might be to not name the indices with the time stamp but instead a slugified version of the very item that you check/uncheck. I.e “Replace batteries” would become “replace-batteries”. There is the slugify operator for this.

@twMat Thanks. We have the solution, it seems.

And thanks even more because during the process, you showed the use of several techniques that will come handy in many other situations also.

For fun given your request I created this; the second may be very close to your intended use.

<$list filter="[[q1]] [[q2]] [[q3]] [[Proceed?]]" variable=question>
   <$checkbox field=<<question>> checked=<<question>> unchecked="" default=""> <$text text=<<question>>/></$checkbox><br>
</$list>

However I came up with this single tiddler, but it requires 5.2.0 for unlimited fieldnames.
quicklist.json (420 Bytes)

Now create a tiddler and tag it quicklist;

  • every line you type will gain a checkbox
  • use the fold tiddler button if you only want to see the list
  • Even once checked, you can delete or replace a line and get a new item thus retaining a history.

This is so helpful I am making a more advanced one that allows you to still use other wiki text.

2 Likes

I do what is asked in this thread in The quickest and easiest ever todolist in tiddlywiki ? Requires 5.2.0 - #2 by TW_Tones

1 Like

@TW_Tones Thanks a ton! The quicklist solution is really what the name suggests — quick.

1 Like