Unexpected behavior with savetitle in action-createtiddler widget and set widget.

63 views
Skip to first unread message

Alan Aldrich

unread,
Dec 11, 2019, 6:28:42 PM12/11/19
to TiddlyWiki
Hello everyone,
I am hoping someone can help me figure this out...

Currently the New Table button in my plugin TiddlyTables creates a new tiddler with <<table>> as its text. I would like that to instead be: <<table "title of new tiddler">> where "title of new tiddler" is the title generated by the action-createtiddler widget.

Here is a basic version of what I am attempting:

\define newTableText()
<<table "$(newTableTitle)$">>
\end
<$button>
<$action-createtiddler $basetitle="New Table"
$savetitle
="$:/temp/title"
/>
<$set name="newTableTitle" value={{$:/temp/title}} >
<$action-setfield $tiddler={{$:/temp/title}} text=<<newTableText>>/>
</
$set>
<$action-navigate $to={{$:/temp/title}}/>
<$action-deletetiddler $tiddler="$:/temp/title"/>
New Table</$button>

The problem seems to be with the set widget. I think the variable is getting assigned before $:/temp/title is created. Am I using the set widget incorrectly? Is there another way to accomplish this?

Any help is greatly appreciated!
Alan

Mark S.

unread,
Dec 11, 2019, 8:41:45 PM12/11/19
to TiddlyWiki
I would love it if I'm wrong, but in my experience you can't have the changes created by one action widget then used by another action widget inside the same trigger (button) widget. You would need a 2nd button for the 2nd stage. Hopefully someone will pop up and prove me wrong ;-)

Alan Aldrich

unread,
Dec 11, 2019, 11:12:49 PM12/11/19
to TiddlyWiki
Mark, there is no issue with the action widgets. In fact try this in the above code: replace the value in the set widget with "some static text". Everything works as expected. That is, the setfield action sets the text  of the new tiddler to <<table "some static text">> then navigates to it, then deletes the temp tiddler. The issue appears to be with the set widget. It is as if the set widget is parsed prior to any action widgets regardless of its location inside the button.

Eric Shulman

unread,
Dec 11, 2019, 11:51:32 PM12/11/19
to TiddlyWiki
On Wednesday, December 11, 2019 at 8:12:49 PM UTC-8, Alan Aldrich wrote:
Mark, there is no issue with the action widgets. In fact try this in the above code: replace the value in the set widget with "some static text". Everything works as expected. That is, the setfield action sets the text  of the new tiddler to <<table "some static text">> then navigates to it, then deletes the temp tiddler. The issue appears to be with the set widget. It is as if the set widget is parsed prior to any action widgets regardless of its location inside the button.

Button actions can be subtle, especially when you are depending upon intermediate results *during* the processing of the actions.

Fortunately, there IS a solution to your problem:

You can get the results you want if you split the button processing into two parts:
(1) create the new tiddler, and
(2) set the contents, show the tiddler, and cleanup the temp

Part(1) of the processing is in the body of the $button widget.
Part(2) of the processing is done using the $button widget's "actions" param.

Although Part(1) is not invoked until the button is pressed, it is *parsed* when the $button widget is rendered.
However, because Part(2) is done via a separate "actions" param, it is not even *parsed* until the button is actually pressed.
As a result, Part(1) processing is completed before Part(2) is parsed AND invoked.
This allows Part(2) to use the contents of $:/temp/title that were set during Part (1).

Give this a try:
\define newTableText()
<<table "$(newTableTitle)$">>
\end

\define makeNewTable()

<$set name="newTableTitle" value={{$:/temp/title}} >
<$action-setfield $tiddler={{$:/temp/title}} text=<<newTableText>>/>
</
$set>
<$action-navigate $to={{$:/temp/title}}/>
<$action-deletetiddler $tiddler="$:/temp/title"/>
\end

<$button actions=<<makeNewTable>>>
New Table

<$action-createtiddler $basetitle="New Table" $savetitle="$:/temp/title" />
</$button>

let me know how it goes,

enjoy,
-e

Alan Aldrich

unread,
Dec 12, 2019, 12:59:16 AM12/12/19
to TiddlyWiki
Thanks Eric! This is a very clever solution and it will work perfectly for me.
Much appreciated,
Alan
Reply all
Reply to author
Forward
0 new messages