Help - with basic $checkbox options

I made a simple ToDO tiddler, similar to TaskManagementExample on TW-org, but the version I used differs slightly, so I have some questions about the syntax differences.

  • I understand the code, and everything is working as is, however I want to have the ToDO tag auto-removed when ticked AND if the completed item is unticked the ToDO tag is added back.

From a TW-beginner’s perspective, this would be handy whilst editing. If I decide to change something common to a number of tiddlers, I can quickly unmark any previously complete tiddlers via the completed list.

I’ve read a few $checkbox related posts, also references: CheckboxWidget, and ActionWidgets — but at this stage I don’t have a good grasp of the TW-code syntax.

  • I thought it would simply be a case of replacing $checkbox tag="done"> with $checkbox tag="ToDO"— but that doesn’t work.

    I also tried — <$checkbox tag="done" unchecked="tag[ToDO]"> — fail. I suspect my syntax is a bit messed up.

    How does the widget know to remove the “done” tag when you untick the box?

I’m hoping that what I’d like to do is simple.

  • Lastly, in reference to syntax differences in my opening paragraph, is the use of — <$link to ={{!!title}}> <$view field='title'/> </$link>

    While the TW.org reference is far simpler and appears to do the same thing — <$link/>. Am I misunderstanding something here?

Quick tip (sitting waiting for a train)

Rather than the checkbox widget consider a button with the toggle or cycle operators however you can use the listops operator against the tags field.

You can use the invertTag attribute to invert the logic:

<$checkbox tag="ToDo" invertTag="yes"> ~ToDo ?</$checkbox>

2 Likes

In time I hope to understand, use and appreciate your tip, thanks.

As a beginner, I’m still very much at the stage of needing to understand the code fragments I’m using (if they are actually rudimentary things to know), as found in TW-reference.

The only markup I’ve ever used is HTML with CSS and how to embed PHP/Javascript therein… stuff I’ve not used for a number of years. TW-methods seem to be a mashup of some of those languages. It will take me a bit of time, sorry.

The way I learn best, is to understand and document, then move up to the next level. An analogy - I want to open a drawer, insert something, close the draw. Later I will want to know how to build the draw, automate its function etc. Just not yet! :slight_smile:

1 Like

Sure @Anakowi when responding here it’s hard to judge how much the person who asked the question knows. It’s fine to say you don’t know. That’s how we all started.

1 Like

Here is a fuller solution, place in a tiddler tagged $:/tags/Macro;

\define check-tag(tag:"on" off:"" label:"""<<__tag__>>?""" tooltip)
<$button tooltip="""$tooltip$""" class="tc-btn-invisible">
<$action-listops $field="""tags""" $filter="""[all[current]tags[]toggle[$tag$],[$off$]]"""/>
<$text text={{{ [all[current]tag[$tag$]then[☑]else[☐]] }}}/> $label$
</$button>
\end

Now any where, but most likely in a tiddler tagged $:/tags/ViewTemplate

Use the macro,

  • <<check-tag>> which by default toggles the “on” tag, or removes it.
  • <<check-tag done>> to use another tag.
  • <<check-tag done ToDo>> to use another tag Include the off:“value” to approximate your original Question
  • The default label is the “tagname?” but you can provide your own.
  • The full form of the macrocall including defaults is;
    <$macrocall $name="check-tag" tag="on" off="" label="<<__tag__>>?" tooltip=""/>
  • Yes <$link/> is the short form of the above or more precisly;
    <$link> <$text text=<<currentTiddler>>/> </$link>
    • The current tiddler is the default “to”, the text widget ensures if the title contains caAmeL case it will not show as a tiddler link.
1 Like

I am curious, why are you using triple quotation marks in this macro? Any functional reason or just stylistic preference?

I did not give it too much thought to it, however now fieldnames have almost unlimited naming characters, the triple quotes used in code allows the parameter to include single or double quotes. One advantage of fieldnames now is they can also be equivalent to a tiddler name and whilst I avoid any quotes in tiddler names, I may want to use tiddler names as field names one day.

  • It just kind of future proofing :nerd_face:

Extending this idea consider a fieldname that is also a tiddler name, then the value of that field could be the relationship this tiddler has, to that tiddler.

Oh, because macro substitution works via a simple search and replace at the start of execution, before the component tree is built - I never use it so I wouldn’t know.

Thanks @Mark_S — LOL - I like the look of simplicity BUT still not quite the behaviour I want.

invertTag is NOT mentioned in TW’s library of references. Is that a made-up variable?

A big part of my problem is I don’t understand what each part of the syntax does.

I see that it does remove the ToDO tag from the tiddler, but leaves me with an unchecked list item. I’m fiddling to see what happens.

I feel that having a selected list of items that I can view in one tiddler as complete/incomplete is very useful, quite apart from finding “missing” or “orphan” tiddlers.

I will add the complete code I’m using in my OP above – to better explain what I’m doing.

Ah - well I wasn’t permitted to edit my OP. So here is the code I’m trying to UNDERSTAND and Improve.

ToDO — list of Tiddlers to review
Each tiddler in the list is tagged “ToDO”

<$list filter="[!has[draft.of]tag[ToDO]!tag[done]sort[created]]">
<$checkbox tag="done"> <$link/>
</$checkbox></$list>

Done — completed list of Tiddlers (reviewed)
Each tiddler in the list is now tagged “done” with checkbox ticked.

<$list filter="[!has[draft.of]tag[done]sort[created]]">
<$checkbox tag="done"> ~~<$link/>~~
</$checkbox></$list>

And to reiterate, what I’d like to happen is when the item is complete the “ToDO” tag is removed from the tiddler AND if the completed item is unticked, the “ToDO” tag is added again (which is already happening).

Thank you — I’m also going to test this out. There’s so much in this code that I don’t understand (yet).

It now occurs to me that I need to make a separate wiki for testing so I don’t break the one I’ve spent weeks perfecting.

Just create the tiddler and dont tag it $:/tags/Macro and test the macro in the same tiddler.

  • It only defines the macro check-tag and if you don’t already have it, or don’t use a macro call to it, it will not influence your wiki.
  • My believe my macro satisfies your request, or can be made to.

It’s defined in https://tiddlywiki.com/#CheckboxWidget

What reference are you using?

The solution should be this:

<$checkbox field="tags" checked="done" unchecked="todo">This is a task</$checkbox>

…but there’s a bug in the current TW version (5.2.3) that prevents <$checkbox> widget to work as expected with the tags field. This might be related to this bug report but I’m not sure.

Anyway, if you replace the tags field with another non-system field, say result, the checkbox works as expected:

<$checkbox field="result" checked="done" unchecked="todo">This is a task</$checkbox>

{{!!result}}

In order to bind 2 tags to the [un]checked state of a <$checkbox> widget, this is a working solution, at least in a single new tiddler on tiddlywiki.com:

<$checkbox
  tag="done"
  checkactions="""<$action-listops $tags="-todo"/>"""
  uncheckactions="""<$action-listops $tags="todo"/>"""
>This is a task</$checkbox>

Fred

1 Like

eek! :stuck_out_tongue_winking_eye: … that one.

I’ll use this, many thanks @tw-FRed — and also to everyone who’s offered suggestions. You’ve all given me some angles to help me learn the syntax.

Having chased-my-tail inside the “contents” list on tw.com, I believe I’ve found a logical starting point … Concepts > Railroad diagrams, and then I’ll work my way through the alphabetical listing inside Concepts. I wish the learning pathway was better defined for a non-coder.

Please note, My Macro solution above is doing much of what everyone else suggested later in the thread but with easy to use parametrisations and a pseudo checkbox using a single button, as a result it is highly extensible.

  • It allows toggle one/no tag, or toggle between two tags as per the OT
  • Automatic but overridable label
  • Optional tooltip

To all;
There is also a new feature Release 5.2.3 in the checkbox widget the listField which could be used to manipulate the tags field and is a way to avoid the listops action, or have a checkbox toggle the existence of items within a list field like the tags field.

Looked that one up… my brain froze. I don’t doubt that the macro method is good if one understands it. :pray:

Currently reading $action-listops — too much, too soon to even begin to understand. My conclusion (for now) is I don’t care what it does, FRed’s code is short, simple and is working. I can keep going with TW rather than give up.

Just to be clear you don’t have to understand it, to just use it;

<<check-tag done toDo>>

  • On first click will indicate its done (adds done tag)
  • If you untick it, it will no longer be done and tag it ToDO, you can again click done
  • If already tagged ToDo it will simply display unticked or not done.

However if you can only use it if you understand it, do what you will.

Also if the behaviour is not what you expected describe it in english not partial code and we can give you exactly what you want. For example No where I could see did you mention what to do if there was no ToDO tag to start with.

If you are interested in the wisdom of someone experienced here I would use the following logic;

  • Avoid using tags to indicate status and keep them free for ad hoc organising
  • if the field done-date exists and its empty show it is to be done
  • Provide a button to mark it done that date stamps the done-date with a date/time stamp <<now YYYY0MM0DD0hh0mm0ss0XXX>>

In your lists items that need doing are found with the filters;

  • [all[tiddlers]has[done-date]] will return only done tiddlers title, but also the exact date/time it was done is available with {{!!done-date}} suitable formatted
    ** [all[current]get[done-date]] will return only done tiddlers but also the exact date/time it was done
  • [all[tiddlers]has:field[done-date]!has[done-date]] will only list tiddlers that have the done date field but with no value - it is not done, but should be.

You could have a button called “redo” that only appears on tiddlers with a done-date with a value, which would set the done-date to empty "" and could first save done-date to last-done-date or update a data tiddler with date/time tiddler/done/undone and have a infinite history available.

I may write a macro to support this!

Fair enough, but I’m still unable to implement BECAUSE I’m still a bit lost with where and how to actually do so. BUT you do describe exactly what I want to have happen. Thanks.

If a tiddler has no ToDO or DONE tags, then the tiddler needs no further editing/review. I suppose the concept suits tiddlers/wiki still under development.

Thanks, it makes sense to not use TAGS when there are other methods, but I’m still weeks/months/years away from appreciating how I might use existing field-data. TW is a hobby and I’m struggling.

Sorry, it must be frustrating to help someone like me.