TW5: New Tiddler From Button With Custom User Fields Added

1,400 views
Skip to first unread message

tdymon...@gmail.com

unread,
Mar 15, 2017, 3:04:33 AM3/15/17
to TiddlyWiki
I'm a long time user of classic TiddlyWiki, but am new to TW5. I'm trying to create buttons for different journal types, e.g., personal, fitness, food. I've used the existing documentation I could find on tiddlywiki.com and this forum to successfully create the button that creates the new journal tiddler with the title I want, which is a journal type specific prefix to the current date and time, and tags. The generated tiddlers are automatically opened for editing.

I'm having a bit of difficulty adding custom fields to the button generated new tiddlers. What i'm wanting is for the custom fields to appear, along with their pre-assigned values, in the newly generated tiddlers that are open for editing. I don't want to have to add the custom fields and values manually after creation or saving. In other words, to create an entry in the journal I only want to have to hit the New Journal button (for the desired journal type), type the text of the entry and hit save without having to do anything else.

For instance:

Title: Fitness-YYYYMMDDHHMMSS
Tags: Journal, Additional Tags...
Text: empty

Which is working at this point. But I also want custom user fields:

journal-type: (E.G., personal, fitness,
journal-part: (E.G., segment, entry)
year: 2017
month: 03
day: 14

Which I can't figure out how to do.

I've tried using the $fieldmangler and action-setfield within the button code, to no effect. It doesn't add any fields the the newly created and opened for editing tiddler.

I've spent hours on this forum searching for an answer, as well as a lot of additional hours on Google searching, but to no avail. Any help or directions to help would be greatly appreciated.

Ultimately, my goal is to use the custom fields to automatically add the entries of the journals into the TOC, which I'm doing now with tags, with a hierarchy of journal type, year, month and day, in order to alleviate the amount of bloat to my tags. However, for right now, I'll just be happy to get the code for the new journal buttons working correctly.

Below is the current code for the button: The title of this tiddler is $:/me/Buttons/NewFitness and it is tagged $:/tags/PageControls

\define journalButton()
<$fieldmangler>
<$button tooltip={{$:/me/language/Buttons/NewFitness/Caption}} aria-label={{$:/me/language/Buttons/NewFitness/Caption}} class=<<tv-config-toolbar-class>>>
<$action-setfield journal-type="fitness" journal-part="segment"/>
<$action-sendmessage $message="tm-new-tiddler" title=<<now "DEL-$(journalTitleTemplate)$">> tags="$(journalTags)$"/>
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-journal-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>prefix[yes]]">
<span class="tc-btn-text"><$text text={{$:/me/language/Buttons/Fitness/Caption}}/></span>
</$list>
</$button>
</$fieldmangler>
\end
<$set name="journalTitleTemplate" value={{$:/config/NewJournal/Title}}>
<$set name="journalTags" value="Journal">
<<journalButton>>
</$set></$set>

The only part of this that doesn't work is adding the custom fields to a newly created tiddler. Thank you in advance for your help.

Eric Shulman

unread,
Mar 15, 2017, 3:51:28 AM3/15/17
to TiddlyWiki
On Wednesday, March 15, 2017 at 12:04:33 AM UTC-7, tdymon...@gmail.com wrote:

create an entry in the journal I only want to have to hit the New Journal button (for the desired journal type), type the text of the entry and hit save without having to do anything else.

 

For instance:

Title: Fitness-YYYYMMDDHHMMSS
Tags: Journal, Additional Tags...
Text: empty

Which is working at this point.  But I also want custom user fields:

journal-type: (E.G., personal, fitness,
journal-part: (E.G., segment, entry)
year: 2017
month: 03
day: 14

Which I can't figure out how to do.


Try something like this:

<$button>
<$action-sendmessage $message="tm-new-tiddler"
   title=<<now "DEL-$(journalTitleTemplate)$">>
   tags="$(journalTags)$"

   text=""
   journal-type="fitness"
   journal-part="segment"
   year: <<now "YYYY">>
   month: <
<now "0MM">>
   day: <
<now "0DD">>
/>
New Tiddler
</$button>

let me know how it goes...

enjoy,
-e
Eric Shulman
TiddlyTools: "Small Tools for Big Ideas" (tm)
InsideTiddlyWiki: The Missing Manuals

J Mc

unread,
Mar 15, 2017, 4:13:00 AM3/15/17
to TiddlyWiki

Eric Shulman

unread,
Mar 15, 2017, 4:42:45 AM3/15/17
to TiddlyWiki
errata: sample code should be:

<$button>
<$action-sendmessage $message="tm-new-tiddler"
   title=<
<now "DEL-YYY0MM0DD">>
   tags="journal"

   text=""
   journal-type="fitness"
   journal-part="segment"
   year=<<now "YYYY">>
   month=<
<now "0MM">>
   day=<
<now "0DD">>
/>
New Tiddler
</$button>



(replaced erroneous ":" with "=" in last three param declarations)

-e

PMario

unread,
Mar 15, 2017, 5:21:02 AM3/15/17
to tiddl...@googlegroups.com
Hi tdymon,
Hi Eric,

The example Eric posted is good for the described usecase but there is a little problem: The <<now>> macros are evaluated, when the button is drawn. So if the date changes and you click the button, you'll get what is defined, but it may be unexpected.
If you show the button in a tiddler, there may be no big difference. But if the button is part of the sidebar, which isn't redrawn that often, it may cause confusion at around midnight :)

This does the same thing, but evaluates the now macros when you click the button: .. I did change day and month to min and sec .. to see the difference

\define myNewJournal()

<$action-sendmessage $message="tm-new-tiddler"
   title=<<now "DEL-YYY0MM0DD">>
   tags="journal"

   text=""
   journal-type="fitness"
   journal-part="segment"

   min=<<now "0mm">>
   sec=<<now "0ss">>
/>
\end

<$button actions=<<myNewJournal>> >
New Tiddler
</$button>


Also see: http://tiddlywiki.com/#ActionWidgets

have fun!
mario

tdymon...@gmail.com

unread,
Mar 15, 2017, 5:29:13 AM3/15/17
to TiddlyWiki
I've consolidated your code into what I already had:

\define journalButton()
<$button aria-label={{$:/me/language/Buttons/NewFitness/Caption}} class=<<tv-config-toolbar-class>>>
<$action-sendmessage
$message="tm-new-tiddler" title=<<now "Fitness-$(journalTitleTemplate)$">> tags="Journal" journal-type="Fitness" journal-part="segment" year=<<now "0YYYY">> month=<<now "0MM">> day=<<now "0DD">>/>


<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-journal-button}}
</$list>
<$list filter="[<tv-config-toolbar-text>prefix[yes]]">

<span class="tc-btn-text"><$text text={{$:/me/language/Buttons/NewFitness/Caption}}/></span>
</$list>
</$button>


\end
<$set name="journalTitleTemplate" value={{$:/config/NewJournal/Title}}>

<<journalButton>>
</$set>

...and it works perfectly! Thank you very much Jeremy and great job with TW5!

tdymon...@gmail.com

unread,
Mar 15, 2017, 5:35:41 AM3/15/17
to TiddlyWiki
Oops, my sincerest apologies Eric for accidentally calling you Jeremy. I guess I should read more than just the body of the replies, lol. Please forgive me.
Reply all
Reply to author
Forward
0 new messages