Target tiddler exists warning

Hello good people

When a new tiddler is created using the + at the top of the sidebar, a message appears in the draft tiddler if the target tiddler already exists.

However, when a new tiddler is created using the tm-new-tiddler widget message no such message appears

The code I have used in my testing is

\define NewJournalEntry()
<$action-sendmessage $message="tm-new-tiddler"
   title={{!!date}}
   tags="Journal"
   date={{!!date}}
/>
\end

Pick date for new journal entry

<$macrocall $name="edit-date" tiddler=<<currentTiddler>> field="date" type="button" format="YYYY-0MM-0DD" inputActions=<<NewJournalEntry>> />

<$view field="date"/>

Can anyone explain why this is and how it can be rectified.

Many thanks

Because we (well, me for sure) don’t have the "edit-date"macro, it is very hard to troubleshoot your code (and/or make suggestions) if we can’t do anything with it.

Aside: should a tiddler with that title already exist, what do you want to happen ?

The edit-date macro is here: TiddlyTools/Time/EditDate

However, the issue raised by @Rob_Jopling is not caused by my TiddlyTools macro. It can be replicated simply by using one of the examples from https://tiddlywiki.com/#WidgetMessage: tm-new-tiddler

<$button>
<$action-sendmessage $message="tm-new-tiddler" title="This is newly created tiddler" tags="OneTag [[Another Tag]]" text=<<now "Today is DDth, MMM YYYY">>/>
New Tiddler
</$button>
  • Press the above $button to create “This is newly created tiddler”
  • Add some extra content in the text field
  • Press “done” to finish editing
  • Press the above $button again
  • Note that it automatically replaces the existing tiddler (the extra content you added is GONE!). This is why it does not show the “tiddler already exists” warning.

You can avoid this “overwrite” situation by using the $action-createtiddler widget instead of the tm-new-tiddler message in your NewJournalEntry() macro, like this:

\define NewJournalEntry()
<$action-createtiddler $basetitle={{!!date}} tags="Journal" date={{!!date}}>
   <$action-sendmessage $message="tm-edit-tiddler" $param=<<createTiddler-title>>/>
</$action-createtiddler>
\end

When invoked, the $action-createtiddler widget will create a new tiddler with the chosen date (e.g. “2024-11-23”). If the specified tiddler title already exists, a number will be automatically added to the end of the title (e.g., “2024-11-23 1”, “2024-11-23 2”, etc). The tm-edit-tiddler message will then open it for editing. If, while editing, you remove this extra number from the title, the “tiddler already exists” message will appear and when you press done to finish editing, you will be asked to confirm “Do you wish to overwrite…”

Another alternative would be to use:

\define NewJournalEntry()
<% if [{!!date}is[missing]] %>
   <$action-sendmessage $message="tm-new-tiddler" title={{!!date}} tags="Journal" date={{!!date}}/>
<% else %>
   <$action-sendmessage $message="tm-edit-tiddler" $param={{!!date}}/>
<% endif %>
\end

When invoked, this code will either create a new tiddler with the specified title, or edit the existing tiddler if it already exists. Any content previously entered into that tiddler will be retained.

enjoy,
-e

2 Likes

Hey, I was not insinuating your macro was causing the problem.

I was indicating that it is impossible to test/troubleshoot that segment of code (and/or make suggestions) without having all of the bits and pieces needed for that code to work.

Very cool, though, if others want to add the missing bits and pieces. That’s just not my cup o’ tea.

I did not feel that you were “insinuating” my macro as the cause.

However, as I demonstrated in my response, it absolutely IS possible to test/troubleshoot the problem even without my edit-date macro, by first focusing on the TWCore’s tm-new-tiddler handling rather than being concerned with how it is being invoked. Of course, if that initial simplified test had failed to replicate the problem, then it would have been necessary to get my TiddlyTools macro to fully test the code in the OP.

-e

The message tm-new-tiddler does not have a warning, because it assumes that the programmer takes care of the test for existing tiddlers.

There are several possibilities to avoid to overwrite existing tiddlers.

  1. You can use the https://tiddlywiki.com/#ActionCreateTiddlerWidget, which does create a new tiddler name by default. If you want to overwrite existing tiddlers, you will need to use the “overwrite” parameter
  2. Let’s assume we use the button-widget to create a new tiddler actions. The widget has a “disabled” parameter, which can contain a filter, that disables the button, if a tiddler-title already exists.
  3. unusedtitle macro can be used to create a unique name for new tiddlers. No 1. has a similar but simpler mechanism built in.

I would suggest option 1, which gives you more fine grained control than tm-new-tiddler.

2 Likes

Many thanks for clarifying this.