Switch a Tag among few tiddlers

74 views
Skip to first unread message

Mohammad

unread,
Jul 2, 2019, 5:28:54 AM7/2/19
to TiddlyWiki
 Assume you have
  • Tid1
  • Tid2
  • Tid3
  • Tid4
User wants to have a select widget and choose one Tiddler
  1. The action after selection is to add a Tag like myTag to selected tiddler
  2. In the next round if user chooses another tiddler, the tag (myTag) from previous tiddler shall be removed and new selected tiddler should tagged with myTag
  3. and this will be continued
  • At any time only one tiddler is tagged with myTag


Pseudo code
<$select 
  tooltip="select a tiddler"
  tiddler="mystate" 
  field="myselection"
  actions=<<applyTag>>
>
<$list filter="myfilter" variable="tid">
<option value=<<tid>> > <<tid>> </option>
</$list>
</$select>




/Mohammad

Mohammad

unread,
Jul 2, 2019, 5:57:16 AM7/2/19
to TiddlyWiki
Any idea? Any simple solution?

Mohammad

unread,
Jul 2, 2019, 7:14:46 AM7/2/19
to tiddl...@googlegroups.com
In simple words this is an equal to

Temp = A
A = B
B = Temp

Temp is a temporary variable!
In TW seems everything is dynamic, so I failed to do above operation!

TonyM

unread,
Jul 2, 2019, 7:19:10 AM7/2/19
to TiddlyWiki
Mohammad,

I was wondering if you post was a question.

I have gone down this path before but now days I would swap it around

Have a tiddler tagged 
  • Tid1
  • Tid2
  • Tid3
  • Tid4
Lets call this the set-tiddler

Then use a filter in a select widget to set a field to only one of the above values tagging[set-tiddler]

Then if you want you could change the select filter to not even list the currently selected tiddler, just the balance.

Then if you get smart you could make next, previous, first and last buttons. I will do this one day as an essential code pattern but not right now.

Regards
Tony

Mohammad

unread,
Jul 2, 2019, 7:48:40 AM7/2/19
to TiddlyWiki
Sorry! You are right I forgot to ask the question in original post!
I send two more posts after that and asked my question!
In real case they are tens of tiddlers and may grow dynamically all have no Tag except one!
Then user select another one so this new new gets the Tag and from the previous Tag is removed!

Mohammad

unread,
Jul 2, 2019, 8:10:19 AM7/2/19
to TiddlyWiki
The dummy solution is to
  • remove tag from all tiddlers
  • set the tag for select tiddler
The bad part is while only one tiddler has a tag, but I have to process all of them.

--Mohammad

Mohammad

unread,
Jul 2, 2019, 8:57:00 AM7/2/19
to TiddlyWiki
I think this may be a solution

\define applyTag()
<!-- first remove tag -->
<$list filter="[search:title[exmp65/data]tag[exmp65]]">
<$fieldmangler>
<$action-sendmessage $message="tm-remove-tag" $param="exmp65"/>
</$fieldmangler>
</$list>
<!-- then add tag -->
<$tiddler tiddler={{exmp65/state}}>
<$fieldmangler>
<$action-sendmessage $message="tm-add-tag" $param="exmp65"/>
</$fieldmangler>
</$list>
</$tiddler>
\end

;How swith a tag among a set of tiddlers? Only one tiddler can have the tag at a time!
: The solution is to use `select` widget and an action macro

The below example demonstrate how to switch a tag among set of tiddlers. The code has two parts

# select widget to choose one tiddler among set of tiddlers
# action macro to set tag to the selected tiddler and remove it from previous tiddler

Here for this example, tag `exmp65` between three tiddlers is switched. Only one tiddler has the tag at a time. The action macro called `applyTag`.




<$macrocall $name="wikitext-example-without-html" 
src="""<$select 
  tooltip="select a tiddler"
  tiddler="exmp65/state" 
  field="text"
  actions=<<applyTag>>
>
<$list filter="[search:title[exmp65/data]]" variable="tid">
<option value=<<tid>> > <<tid>> </option>
</$list>
</$select>
"""/>




This may be not optimized code but work!


Mohammad

unread,
Jul 2, 2019, 8:59:46 AM7/2/19
to TiddlyWiki
Example attached!

Give your comment or alternative solution!
switch-tag.json

PMario

unread,
Jul 2, 2019, 6:02:37 PM7/2/19
to TiddlyWiki
Hi,

You may have a closer look at: https://tiddlywiki.com/#ActionListopsWidget

-m

Mohammad

unread,
Jul 3, 2019, 1:28:36 AM7/3/19
to TiddlyWiki
Thanks Mario!
 I will have a closer look and will share if I could introduce better solution!

--Mohammad
Reply all
Reply to author
Forward
0 new messages