[TW5] How to use checkbox to add to list field

1,279 views
Skip to first unread message

infurnoape

unread,
Feb 23, 2016, 7:24:52 PM2/23/16
to tiddl...@googlegroups.com

Hello everyone,
I'm trying to add to the list field using the checkbox widget and can't figure out how to write it. Currently I have tried the following. But it fails. Any suggestions?

\define add()
<$action-listops $tiddler="$:/plugin/ajh/format/list" $field="list" $subfilter="[[$(currentTiddler)$]]"/>
\end
\define remove()
<$action-listops $tiddler="$:/plugin/ajh/format/list" $field="list" $subfilter="-[[$(currentTiddler)$]]"/>
\end

<$set name="tv-config-toolbar-icons" value="yes">

<$set name="tv-config-toolbar-text" value="yes">

<$list filter="[all[shadows+tiddlers]tag[$:/tags/FormatToolbar]!has[draft.of]]" variable="listItem">

<$checkbox tiddler="$:/plugin/ajh/format/list" field="list" checked=<<add>> unchecked=<<remove>> default=<<add>/> <$transclude tiddler=<<listItem>> field="caption"/> <i class="tc-muted">-- <$transclude tiddler=<<listItem>> field="description"/></i>

</$list>

</$set>

</$set>

Happy Connecting. Sent from my Sprint Samsung Galaxy S® 5

Scott Simmons (Secret-HQ)

unread,
Feb 23, 2016, 9:46:17 PM2/23/16
to TiddlyWiki
Hi, Andrew —

I think the problem stems from trying to pass a variable ($(currentTiddler)$) into the <$action-listops> widget.

I'm not sure how to get around that using only core code — but if you install Tobias's setvars plugin ( http://tobibeer.github.io/tw5-plugins/#setvars ), you can use it to pull in the value of $(currentTiddler)$ and build a literal string that will work.  Like so:

\define add()
<$setvars _currentTiddler=$(currentTiddler)$ listops-string="""\<$action-listops $tiddler="$:/plugin/ajh/format/list" $field="list" $subfilter="[[\ currentTiddler \]]" />\""">
<<listops-string>>
</$setvars>
\end

Matabele

unread,
Feb 23, 2016, 10:39:54 PM2/23/16
to TiddlyWiki
Hi Andrew

The $checklist widget might meet your requirements -- the widget extends the functionality of the $checkbox widget to handle lists in ordinary fields and indexes. There is, therefore, no need to use the $listops widget, provided that your requirement is only to toggle the value of one of the items in a list.

The $checklist widget may be found here.

regards

Eric Shulman

unread,
Feb 23, 2016, 11:22:46 PM2/23/16
to TiddlyWiki
On Tuesday, February 23, 2016 at 4:24:52 PM UTC-8, Andrew wrote:
I'm trying to add to the list field using the checkbox widget and can't figure out how to write it.

The $checkbox widget doesn't invoke action widgets like a $button does... it only allows you to set/clear a field value or add/remove a tag from a tiddler.... and the 'checked', 'unchecked' and 'default' params are supposed to be literal values to be assigned to the indicated field or tag, not $action-* widgets.  Thus, you can't use the $checkbox widget to do what you want.  

You might try using two $buttons to invoke the $action-listops... one button to add the item, the other to remove it.

Wrap each $button inside a $reveal to test to see if the item is present or not, so that only one of the buttons is displayed at any given time.

Use class="tc-btn-invisible" to remove the button styling, and use HTML syntax to show a fake checkbox as the label "text" to show the "checked" vs "unchecked" status of each button:
<input type="checkbox">
<input type="checkbox" checked="checked">

That should allow you to achieve the goal of *appearing* to have checkboxes that toggle a value in a list field.

-e


Scott Simmons (Secret-HQ)

unread,
Feb 23, 2016, 11:50:52 PM2/23/16
to TiddlyWiki
Hmmm.  Looking further down the code, I see you're running into the same issue with the <$checkbox> widget, too.  You won't be able to run your <<add>> and <<remove>> macros within the <$checkbox> widget.  (I learned this the hard way myself.)

There may be a solution using just the core, but I don't know what it is.  I ran into a similar wall a while back, before I discovered <$setvars>, which I now use to build a lot of widget calls pseudodynamically.  Between that and feedback from Matabele, Jed, and Eric on my earlier thread, I came up with a solution something like this:


It uses the <$reveal> widget to display a "faux" checkbox that appears to be either checked or unchecked depending on whether the tiddler you're adding to the list has a certain tag (isTiddlerInFormatList) with a value set to yes.  "Checking" the box sets that field and adds the referenced tiddler to the list field of that FormatList tiddler.  "Unchecking" it empties the isTiddlerInFormatList field and removes the referenced tiddler from that list field.  (Tick the button on the test tiddler and check the fields on the other tiddlers to see how it works — and if that works out for your larger project.)

Andrew

unread,
Feb 24, 2016, 12:28:54 AM2/24/16
to TiddlyWiki
Thank you all. Not sure what lingo-base() is for yet, and I have to make it more readable, so if anyone wants to help with that it would be much appreciated, but I ended up with:

\define lingo-base() $:/language/TiddlerInfo/
\define add() [[$(currentTiddler)$]]
\define remove() -[[$(currentTiddler)$]]

{{$:/language/format/hint##controlpanel}}

<$set name="tv-config-toolbar-icons" value="yes">

<$set name="tv-config-toolbar-text" value="yes">

<$list filter="[all[shadows+tiddlers]tag[$:/tags/FormatToolbar]!has[draft.of]]">

<$list filter="[list[$:/plugin/ajh/format/list]is[current]]"><$button tooltip={{$:/language/Buttons/Format/Hint}} aria-label={{$:/language/Buttons/Format/Caption}} class=<<tv-config-toolbar-class>>>
<$action-listops $tiddler="$:/plugin/ajh/format/list" $field="list" $subfilter=<<remove>>/><input type="checkbox" unchecked="true"/></$button></$list><$list filter="[all[current]!list[$:/plugin/ajh/format/list]]"><$button tooltip={{$:/language/Buttons/Format/Hint}} aria-label={{$:/language/Buttons/Format/Caption}} class=<<tv-config-toolbar-class>>><$action-listops $tiddler="$:/plugin/ajh/format/list" $field="list" $subfilter=<<add>>/><input type="checkbox" checked="true"/></$button></$list>
<$transclude tiddler=<<currentTiddler>> field="caption"/><i class="tc-muted"> -- <$transclude tiddler=<<currentTiddler>> field="description"/></i>

</$list>

</$set>

</$set>

Eric Shulman

unread,
Feb 24, 2016, 12:51:02 AM2/24/16
to TiddlyWiki
On Tuesday, February 23, 2016 at 9:28:54 PM UTC-8, Andrew wrote:

...<input type="checkbox" unchecked="true"/>

 ...<input type="checkbox" checked="true"/>

The HTML syntax for a checkbox does *not* have an "unchecked" attribute.  Also, for cross-browser compatibility, use a value of "checked"... not "true".  Thus:

<input type="checkbox">
   and 
<input type="checkbox" checked="checked">

-e

infurnoape

unread,
Feb 24, 2016, 7:34:40 AM2/24/16
to tiddl...@googlegroups.com
Thank you so much Eric, I will modify to correct it. Your help always makes a big difference. Now all I need is a new template to display the buttons from the list field but that would be a different topic.



Happy Connecting. Sent from my Sprint Samsung Galaxy S® 5


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8f3648fe-a56d-492f-9aa2-90765ced5b01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages