Possible to trigger actions with tab selection / deselection?

63 views
Skip to first unread message

Stobot

unread,
Jul 2, 2020, 1:28:57 PM7/2/20
to TiddlyWiki

My use case is that I have built a UI around the tabs macro, but some of my tabs are lists of 'things', and then I have a tab for *viewing* the thing, and one for *editing* the thing using drop downs etc. 

What I ultimately need to happen is for some temp tiddlers to be deleted when a certain tab is selected. I thought I might be able to either:
  1. Add an actions parameter to the <<tabs>> macro to handle when it's changed
  2. Put some raw <$action-...> code not behind a button and have it kind of work as a load event for that tiddler
Neither seem to be possible. Is there some other similar functionality I can use?

Saq Imtiaz

unread,
Jul 2, 2020, 1:37:10 PM7/2/20
to TiddlyWiki
Have you tried using the buttonTemplate parameter of the tabs macro?

Stobot

unread,
Jul 2, 2020, 1:51:10 PM7/2/20
to TiddlyWiki
I haven't, I saw it when trying to figure things out, but how would I use it? Sorry for not understanding... I assumed would somehow allow me to programmatically rename the tab or something?

buttonTemplate: Optionally, the title of a tiddler to use as a template for transcluding the content of the button for the selected tab

Saq Imtiaz

unread,
Jul 2, 2020, 2:01:46 PM7/2/20
to TiddlyWiki
I believe it was originally intended so you could customize what is displayed inside the button.
But you can leverage it to execute actions inside the buttons as well.

in the tabs macro add the parameter for the buttonTemplate and point it towards a tiddler that you create to act as the template for the buttons. buttonTemplate:my-button-template
 
In the template tiddler place the following:
<!--- replace this comment with your actions -->
<$transclude tiddler=<<currentTab>> field="caption">
<$macrocall $name="currentTab" $type="text/plain" $output="text/plain"/>
</$transclude>

You can wrap the actions in a list widget to make sure you execute the correct actions for the correct button.

Stobot

unread,
Jul 2, 2020, 2:07:32 PM7/2/20
to TiddlyWiki
Perfect! Exactly what I was looking for - thanks Saq!!

TW Tones

unread,
Jul 2, 2020, 7:46:46 PM7/2/20
to TiddlyWiki
Saq,

How many times did you have to read?

Optionally, the title of a tiddler to use as a template for transcluding the content of the button for the selected tab

Its English, but not meaningful, it introduces a concept at the very end, "the Button?" Perhaps it should start with tabs are themselves buttons defined in the tabs macro...

I am sure I can workout what its trying to say by looking at $:/core/macros/tabs

Regards
Tony

TW Tones

unread,
Jul 2, 2020, 7:46:59 PM7/2/20
to TiddlyWiki
Stobot,

Saq seems to have solved this for you, but I would like to point out there is sufficient customisation in tiddlywiki you could build you own tabs macro with the tab titles being buttons and use those buttons actions parameter as well. If you see here $:/core/macros/tabs that's exactly what the tabs macro does.

Regards
Tony

Stobot

unread,
Jul 2, 2020, 10:02:13 PM7/2/20
to TiddlyWiki
Thats a great point Tony. I'll take a look. Thanks.

TW Tones

unread,
Jul 2, 2020, 10:18:55 PM7/2/20
to TiddlyWiki
Stobot,

I think its time for an updated tab macro, that also uses icon, color, tooltip and named actions (tab-actions field?) of the tabTiddler if it exists and if clicked on.

Regards
Tony

Saq Imtiaz

unread,
Jul 3, 2020, 1:43:00 AM7/3/20
to TiddlyWiki
Hi Tony,


On Friday, July 3, 2020 at 1:46:46 AM UTC+2, TW Tones wrote:

How many times did you have to read?

Optionally, the title of a tiddler to use as a template for transcluding the content of the button for the selected tab

Just once, but I welcome a docs PR from you if you feel it needs to be explained better.
Cheers,

Saq

TW Tones

unread,
Jul 3, 2020, 1:46:06 AM7/3/20
to TiddlyWiki
Saq,

Its brave of me to say of course, "that I do not understand the sentence", even some punctuation may help. The problem is one needs to understand it to document it. 

Regards
TW Tones
Reply all
Reply to author
Forward
0 new messages