[TW5] Now date not refreshing in button

84 views
Skip to first unread message

Mal

unread,
Jan 13, 2019, 2:35:21 AM1/13/19
to TiddlyWiki
Well, here is a problem that has me a bit baffled.

I have a button that creates a new tiddler with a timestamped prefix as in the following code snippet:

<$button>
<$wikify name="Title" text="""$:/prefix/<
<now YYYY0MM0DD0hh0MM0ss>>/MyNewTiddler""">
<$action-createtiddler $basetitle=<
<Title>> $savetitle="$:/temp/saveTid"/>
</$wikify>
Create New Tiddler
</$button>

When I click on the button it creates the new tiddler as expected.  However, if I click a second time, it tries to create a new tiddler with the same title as the first tiddler and I end up with a new tiddler with " 1" appended to it's title.  This continues, with subsequent tiddlers receiving increasing suffix numbers.

As part of my debugging, I added the line "<$action-setfield newtitle={{$:/temp/saveTid}}/>" after the "action-createtiddler" line and now the button is working as expected with a new timestamp every time the button is pressed.  I don't understand how this change could possibly affect the operation of the "now" macro.

Any suggestions welcome.

Regards,

Mal

TonyM

unread,
Jan 13, 2019, 2:59:04 AM1/13/19
to TiddlyWiki
Mal,

I think it is because the $savetitle is somehow delimiting the end of the previouse parameter.

Tony

TonyM

unread,
Jan 13, 2019, 3:01:20 AM1/13/19
to TiddlyWiki
Ps the suffix that is incremented is by design so you dont delete existing tiddlers. It will not happen when the time is always changing.

Tony

Jed Carty

unread,
Jan 13, 2019, 3:41:55 AM1/13/19
to TiddlyWiki
Macros don't update without an outside trigger. The contents of a button, once rendered, don't necessarily update each time you click the button.

One difference between widgets and macros is that widget are able to trigger their own refresh cycles and update their result without needing other intervention, macros determine their output when they are rendered and don't re-render without some outside influence.

One way to get around your problem is to wrap the button in a widget that would re-render itself when there is an update from the button, another way is to include a widget that updates after the button is pressed inside the button. Both of those will cause the button to be re-rendered after it is used.

In your case the the title of the newly created tiddler is stored in the tiddler $:/temp/saveTid, which changes an attribute of the action-setfield widget and triggers a refresh. But I suspect that the timestamp will be from the previous time you clicked the button, not from when you click the button now, because the button hasn't refreshed since the last time you clicked it.

I don't remember what the solution to this one is.

S. S.

unread,
Jan 13, 2019, 3:52:30 AM1/13/19
to TiddlyWiki
This seems to work most of the time:

<$button>
<$set name="dummyVariable" value={{saveTid}}>
<$wikify name="Title" text="""$:/prefix/<
<now YYYY0MM0DD0hh0mm0ss>>/MyNewTiddler""">
<$action-createtiddler $basetitle=<
<Title>> $savetitle="saveTid"/>
</$wikify>
Create New Tiddler
</$set>
</$button>

Reference: Refresh Current Tiddler

Mal

unread,
Jan 13, 2019, 5:40:54 AM1/13/19
to TiddlyWiki
All,

Thanks for your input on this.  I think I need to spend a bit of time to get my mind around what is happening here, but the suggested code from S. S. does seem to work.

Regards,

Mal

Mal

unread,
Jan 15, 2019, 12:23:19 AM1/15/19
to tiddl...@googlegroups.com


On Sunday, 13 January 2019 18:41:55 UTC+10, Jed Carty wrote:
...But I suspect that the timestamp will be from the previous time you clicked the button, not from when you click the button now, because the button hasn't refreshed since the last time you clicked it.

Jed, You were quite right, I was getting the timestamp from the previous button click!

I don't remember what the solution to this one is.

I don't profess to fully understand what is going on here, but my solution was to break the code into two tiddlers, the button defined as:

<$button actions={{Create new tiddler action}}>
Create New Tiddler
</$button>

and an action tiddler "Create new tiddler action" containing:

<$wikify name="Title" text="""$:/prefix/<<now YYYY0MM0DD0hh0mm0ss>>/MyNewTiddler""">
<$action-createtiddler $basetitle=<
<Title>> $savetitle="$:/temp/saveTid"/>
</$wikify>

This seems to work as intended, with the correct timestamp each time the button is clicked.

Regards,

Mal


Reply all
Reply to author
Forward
0 new messages