My button, which is customisable for each tiddler, requires a refresh before displaying the correct date

I have created a button that allows me to create a subtiddler for the current tiddler, and can be additionally customised by adding fields to a tiddler. On one tiddler I have added a field so that the created subtiddler is created with the current date, like this: MyTiddler/2022-01-10. This is similar to the code for the new journal button.

However, it will often show the wrong date and require a refresh to show the correct one. For example when I clicked the button today it used yesterday’s date. I then clicked the new journal button and it used the correct date, so I am assuming it is a problem with how I’ve implemented the button, but I’m not sure what the issue is.

Subtiddler button code

This is the button I created: $ _ibby_ui_new-note-button.json (1.1 KB) I’ve also copied the code below.

\whitespace trim
<$wikify name="noteTitle" text="""<$macrocall $name="now" format={{{ [all[current]get[note-title]else[ ]] }}}/>""">
<$let currentPrefix={{{ [<storyTiddler>addsuffix[/]addsuffix<noteTitle>] }}} >
	<$button
		tooltip="Create new subtiddler note"
		aria-label="New note"
		class=<<tv-config-toolbar-class>> >
		<$action-sendmessage 
			$message="tm-new-tiddler" 
			title=<<currentPrefix>> 
			tags={{{ [all[current]get[note-tags]else[Note]] }}} />
			<$list filter="[<tv-config-toolbar-icons>match[yes]]">
			  {{$:/ibby/images/forward-slash}}
			</$list>
			<$list filter="[<tv-config-toolbar-text>match[yes]]">
				<span class="tc-btn-text">New note</span>
			</$list>
	</$button>
</$let>
</$wikify>

Fields used

On the tiddler where I’m experiencing this issue, I used the following fields:

note-tags: 	Note Journal
note-title: 	YYYY-0MM-0DD

Silly questions, may not matter, but what the heck:

What timezone are you in, and what time was it when you pressed the button and got the wrong date ?

I’m in the UTC timezone, and I clicked the button at around 7:30 pm.

That being said, the new journal button used the correct date, and I’ve had the same problem at various times throughout the day, so I think it might be something else.

Just looking at your code. Not sure if I’m reading things right. Somebody correct me if I missed something …

At what point does the wikify happen? As soon as the tiddler showing that button in the toolbar button is rendered.

So “now” is at that very moment.

Whenever the button is pressed could potentially be a long time after the “now” value is retrieved.

Not sure if that is THE problem, but could be A problem. Thoughts?

Yeah, I’m thinking the code for your button needs to be more something like this (I’ve made things a little verbose just for testing purposes):

\whitespace trim
	<$button
		tooltip="Create new subtiddler note"
		aria-label="New note">
		<$action-sendmessage 
			$message="tm-new-tiddler" 
			title={{{ [<now "[UTC]YYYY0MM0DD0hh0mm0ssXXX">format:date[DDth mmm YYYY 0hh:0mm:0ss]addprefix[/]addprefix<storyTiddler>] }}}
			tags={{{ [all[current]get[note-tags]else[Note]] }}} />
Press Me to Create New Tiddler
			<$list filter="[<tv-config-toolbar-icons>match[yes]]">
			  {{$:/ibby/images/forward-slash}}
			</$list>
			<$list filter="[<tv-config-toolbar-text>match[yes]]">
				<span class="tc-btn-text">New note</span>
			</$list>
	</$button>

And yes, obviously,

[<now "[UTC]YYYY0MM0DD0hh0mm0ssXXX">format:date[DDth mmm YYYY 0hh:0mm:0ss]addprefix[/]addprefix<storyTiddler>]

Could be instead:

[<now "[DDth mmm YYYY 0hh:0mm:0ss">addprefix[/]addprefix<storyTiddler>]

When testing/troubleshooting, I’ll more often than not go with the longer code for piecemeal sanity-checking o’ what’s going on.

Pretty and short+sweet is always for post-confirmation-working cleanup refactoring.

The cause of your problem is that the target tiddler title, <<currentPrefix>>, is computed before the $button is rendered AND the $action-sendmessage $message="tm-new-tiddler" is specified inline in the body of the $button. To get the result you want, you need to compute the title when the $button is clicked, which may be at a much later moment in time.

To achieve this, use the actions=... parameter in the $button widget, like this:

\define button_actions()
<$wikify name="noteTitle" text="""<$macrocall $name="now" format={{{ [all[current]get[note-title]else[ ]] }}}/>""">
<$let currentPrefix={{{ [<storyTiddler>addsuffix[/]addsuffix<noteTitle>] }}} >
	<$action-sendmessage 
		$message="tm-new-tiddler" 
		title=<<currentPrefix>> 
		tags={{{ [all[current]get[note-tags]else[Note]] }}} />
</$let>
</$wikify>
\end

<$button
	tooltip="Create new subtiddler note"
	aria-label="New note"
	class=<<tv-config-toolbar-class>>
	actions=<<button_actions>> >
	<$list filter="[<tv-config-toolbar-icons>match[yes]]">
		{{$:/ibby/images/forward-slash}}
	</$list>
	<$list filter="[<tv-config-toolbar-text>match[yes]]">
		<span class="tc-btn-text">New note</span>
	</$list>
</$button>

enjoy,
-e

1 Like

This worked perfectly, and I now understand why it didn’t work before. Thanks a lot Eric and Charlie for your help.

1 Like