New journal button, with $suffix$ and <<now>>

61 views
Skip to first unread message

Lars Solberg

unread,
Jun 9, 2020, 8:20:10 AM6/9/20
to TiddlyWiki
I am trying to create a shortcut to create a bunch of different journal-types. They will have different template-text, titles and so on.
Mostly, the title will contain a suffix coming from an <$edit-text, but they also a macro <<now>>.

Below is what I got so far, it works, but the text-box looses focus after a keypress. I think I am hitting the issue @ https://github.com/Jermolene/TiddlyWiki5/issues/341 (from 2014), but I'm not sure.

Anyone got any idea how to solve this? Or maybe there is a plugin around that does what I want instead?

\define journalLogButton()

<$edit-text tiddler="$:/state/new-journal-log-title" tag="input" default=""/>

<$button>
<$action-sendmessage
  $message="tm-new-tiddler"
  title=<<now "YYYY-0MM-0DD $(titleSuffix)$ ">>
  tags="Journal"
  journal-type="log"
  year=<<now "YYYY">>
  month=<<now "0MM">>
  day=<<now "0DD">>
/>
New log
</$button>

\end

<$set name="titleSuffix" value={{$:/state/new-journal-log-title}}>
<<journalLogButton>>
</$set>

Eric Shulman

unread,
Jun 9, 2020, 8:33:26 AM6/9/20
to tiddl...@googlegroups.com
On Tuesday, June 9, 2020 at 5:20:10 AM UTC-7, Lars Solberg wrote:
I am trying to create a shortcut to create a bunch of different journal-types. They will have different template-text, titles and so on.
Mostly, the title will contain a suffix coming from an <$edit-text, but they also a macro <<now>>.
Below is what I got so far, it works, but the text-box looses focus after a keypress. I think I am hitting the issue @ https://github.com/Jermolene/TiddlyWiki5/issues/341 (from 2014), but I'm not sure.
Anyone got any idea how to solve this? Or maybe there is a plugin around that does what I want instead?

Every keystroke in the $edit-text widget changes the value of $:/state/new-journal-log-title,
which triggers an automatic refresh of everything inside the <$set name="titleSuffix" value={{$:/state/new-journal-log-title}}>
This includes the $edit-text widget itself, which causes the input control to lose focus after each keystroke.

To fix this, simply move the $edit-text widget outside of the <$set>, like this:
 
\define journalLogButton()
<$button>
<$action-sendmessage
  $message="tm-new-tiddler"
  title=<<now "YYYY-0MM-0DD $(titleSuffix)$ ">>
  tags="Journal"
  journal-type="log"
  year=<<now "YYYY">>
  month=<<now "0MM">>
  day=<<now "0DD">>
/>
New log
</$button>
\end

<$edit-text tiddler="$:/state/new-journal-log-title" tag="input" default=""/>
<$set name="titleSuffix" value={{$:/state/new-journal-log-title}}>
<<journalLogButton>>
</$set>

enjoy,
-e

Lars Solberg

unread,
Jun 9, 2020, 8:53:19 AM6/9/20
to TiddlyWiki
yay! It worked!

And thanks for the explaination.

If you don't mind, I'll update the github issue with your explanation as well in case other are looking around as well
Reply all
Reply to author
Forward
0 new messages