New $checkbox listField – bug or user error?

The way I understood the new listField attribute, I can populate e.g. a list of tiddlers by means of checkboxes. When I put this in a New Tiddler on https://tiddlywiki.com/

\define tiddler-list()
<$list filter="[all[shadows]prefix[$:/config]]">
	<$checkbox tiddler="New Tiddler" checked=<<currentTiddler>> listField="list" />
	<$view field="modified" format="date" template="YYYY-0MM-0DD - 0hh:0mm"/> <$link tooltip={{!!description}}><$text text=<<currentTiddler>>/></$link><br>
</$list>
\end

<<tiddler-list>>

I see a list of tiddlers with checkboxes, as expected. Checking one of the boxes also works as expected, with the tiddler title appearing in the list field.
But when I check a second item, I get this:


which is unexpected. I would have thought that the second item also appears in the list.

Have I understood wrongly what the listField attribute is supposed to do?

Have a nice day
Yaisog

PS: When the tiddler attribute points to a non-existent tiddler, I also get a JavaScript error:


I think this is normally handled more gracefully, with the widget not being drawn at all or something similar.

I think it’s a bug, I reported it here : https://github.com/Jermolene/TiddlyWiki5/issues/6871

In the meantime, you can try using a custom field instead of the list field, e.g :

\define tiddler-list()
<$list filter="[all[shadows]prefix[$:/config]]">
	<$checkbox tiddler="New Tiddler" checked=<<currentTiddler>> listField="ConfigList" />
	<$view field="modified" format="date" template="YYYY-0MM-0DD - 0hh:0mm"/> <$link tooltip={{!!description}}><$text text=<<currentTiddler>>/></$link><br>
</$list>
\end

<<tiddler-list>>

This works on the latest version of TW.

3 Likes

@telumire: Thanks for the workaround!

Here’s another error that pops up when unchecking the last item when using the list field:

Another workaround is to use a macro (however I’m sure this will eventually be fixed, sooner or later):

\define checkbox_input(state) <input type=checkbox $state$/>
\define checkbox(value,field:"list",tiddler)
<$tiddler tiddler={{{ $tiddler$ ~[<currentTiddler>] }}}>
    <$button class="tc-btn-invisible" actions="""
        <$action-listops  $field="$field$" $subfilter="+[toggle[$value$]]" />
        """>
    <$macrocall $name="checkbox_input" state={{{ [<currentTiddler>contains:$field$[$value$]then[checked]else[]] }}}/>
    </$button>
</$tiddler>
\end

* <<checkbox A>> A
* <<checkbox B>> B
* <<checkbox C>> C

Demo : Checkbox macro

I Tried you code on Tiddlywiki.com and noticed you are using the “list” field which is a reserved fieldname. Changing this to my-list I was no longer getting the error including for the last item.

I also observe since the list changes the current tiddler it is not appropriate to set tiddler=<<currentTiddler>>unless you want the current tiddler changed, which you seem to. You can use tiddler=<<storyTiddler>> if you just want to add to the local list.

The Bug(s)?

  • If you use the “list” field you get an error on checking more than one item, use another name but a quick test shows the “tags” field also fails.
  • If the tiddler named in the checkbox widget does not exist it fails
    • I think it is just that the checkbox widget will not create a missing tiddler, if you create it first, it does not throw an error.

This is unfortunate because I wanted to use it to manipulate the tags.

As a rule of thumb, the “red screen of embarrassment” always indicates a core bug. It is not supposed to be possible to crash TW just by writing wikitext (all bets are off if there are custom JavaScript modules involved of course).