Toggle and cycle operator - value not in format title

Starting with the example Help - with basic $checkbox options - #6 by TW_Tones about tags, I’ve studied the toggle and cycle operator and I’ve written the following macros:

\define toggle-field(fld:"""myfield""" value:"""[on],[off],[----]""" label:"""""" tooltip:"""""" )
<$button tooltip="""$tooltip$""" class="tc-btn-invisible">
<$action-listops $field="""$fld$""" $filter="""[enlist{!!$fld$}toggle$value$]"""/>
<$text text={{{ [all[current]field:$fld$[]then[-----]else{!!$fld$}] }}} /> $label$
</$button>
\end

\define cycle-field(fld:"""myfield""" value:"""on off""" label:"""""" tooltip:"""?""" )
<$button tooltip="""$tooltip$""" class="tc-btn-invisible">
<$action-listops $field="""$fld$""" $filter="""[enlist{!!$fld$}cycle[$value$]]"""/>
<$text text={{{ [all[current]field:$fld$[]then[-----]else{!!$fld$}] }}} /> $label$
</$button>
\end

but i’m stuck with the problem of space in the field value, in a real case scenario i would use

<<toggle-field fld:"status" value:"[da leggere],[in lettura],[letto]" label:"" tooltip:"libro letto?" >>

and I end with a value in the field of [[in lettura]] or [[da leggere]].

My field aren’t “list field” so I don’t want the value enclosed in square brackets I need: in lettura or da leggere in the field.

Searching https://tiddlywiki.com/#enlist%20Operator was useless.

Please give me an advice. Thank!

The cycle operator works more like this, as shown at the docs

\define cycle-actions()
<$action-listops $tiddler=<<currentTiddler>> $tags="+[cycle[todo soon now maybe done]]" />
\end

<$button actions=<<cycle-actions>> >cycle tag</$button>

have fun!

Yes, but i can not have a value with a space or better i was not able to find a proper syntax to include a value like “well done”.

\define cycle-actions()
<$action-listops $tiddler=<<currentTiddler>> $tags="+[cycle[todo soon now maybe 'well done` done]]" />
\end

<$button actions=<<cycle-actions>> >cycle tag</$button>

@Marco10x15 when you are trying to delimit something such as “well done” inside a filter and it will interfere with the filters format
eg INCORRECT $tags="+[cycle[todo soon now maybe [[well done]] done]]" /> or your example

  • Move this value into a variable for example this works
\define cycle-values() todo soon now maybe [[well done]] done
\define cycle-actions()
<$action-listops $tiddler=<<currentTiddler>> $tags="+[cycle<cycle-values>]" />
\end

<$button actions=<<cycle-actions>> >cycle tag</$button>
  • Inside [cycle<cycle-values>] the set of values is now wrapped inside the variable, so the variable/macro can now include the delimiters for a title with a space [[well done]]
1 Like
\define cycle-actions()
<$let states="[[very low]] low normal high [[very high]]">
<$action-listops $tiddler=<<currentTiddler>> $tags="+[cycle<states>]" />
</$let>
\end

<$button actions=<<cycle-actions>> >cycle tag</$button>

This is the same solution as @TW_Tones with one macro

2 Likes
\define cycle-actions()
<$let states="[[very low]] low normal high [[very high]]">
<$action-listops $tiddler=<<currentTiddler>> $field="myfield" $filter='[enlist{!!myfield}cycle<states>]' />
</$let>
\end

<$button actions=<<cycle-actions>> >cycle myfield</$button> <$text text={{!!myfield}} />

Ok, this is working for tags but the same code used for fields ends with a field filled with [[very low]] when I was searching to fill it with: very low.

Without parentheses or quotation marks.

Try using $action-setfield instead of $action-listops, like this:

<$action-setfield myfield={{{ [enlist{!!myfield}cycle<states>] }}} />
2 Likes
\define cycle-actions()
<$let states="[[very low]] low normal high [[very high]]">
<$action-setfield myfield={{{ [enlist{!!myfield}cycle<states>] }}} />
</$let>
\end

<$button actions=<<cycle-actions>> >cycle myfield</$button> <$text text={{!!myfield}} />

I tried.

With $action-setfield, starting with the field:myfield empty, the first press of the button fill the field with: very low, the second time with: very and then pressing the button has none effect.

ah!.. the problem is the enlist operator, which parses the two words “very low” as two separate input items precisely because they aren’t contained within [[ and ]].

The first time you press the button, {!!myfield} has no value, so cycle<states> defaults to using the first item in <states>, which is “very low”. Then, the 2nd time you press the button, because of enlist{!!myfield}, cycle<states> sees TWO values: “very” and “low”, and since “very” doesn’t match with any of the items in <states>, it just uses the first value from the input and sets myfield to “very”. From then on, it just gets “very” as input, and again, since that value doesn’t match with any of the items in <states>, it continues to result in “very” without changing.

The fix is to leave off the “enlist” operator (since the field value isn’t actually a list!). Try this:

<$action-setfield myfield={{{ [{!!myfield}cycle<states>] }}} />

-e

3 Likes
\define cycle-field(fld:"""myfield""" value:"""on off""" label:"""""" tooltip:"""?""" )
<$let states="$value$" >
<$list filter="[all[current]field:$fld$[]]" >
<$let states={{{ [enlist<states>first[]] }}} >
<$button tooltip="""$tooltip$""" class="tc-btn-invisible">
<$action-setfield $fld$=<<states>> />''$label$'' default to: <<states>>
</$button>
</$let>
</$list>

<$list filter="[all[current]!field:$fld$[]]" >
<$button tooltip="""$tooltip$""" class="tc-btn-invisible">
<$action-setfield $fld$={{{ [{!!$fld$}cycle<states>] }}} />
<$text text="$label$: " /> {{!!$fld$}}
</$button>
</$list>
</$let>
\end

<<cycle-field>>

<<cycle-field "libro" "letto leggere [[in lettura]] [[da rileggere]]" "" "suggerimento">>

<<cycle-field "status" "[[very low]] low normal high [[very high]]" label:"" suggerimento>>

Finally, with your contributions, I solved my problem.

This macro allows you to scroll through a series of values and set the first value in the series if the list is non-existent or empty.

Thank you!

3 Likes

Thanks for contributing back the final solution that worked for you
-m