Edit textbox to append text to another tiddler

155 views
Skip to first unread message

dieg...@gmail.com

unread,
Mar 20, 2021, 3:02:54 PM3/20/21
to TiddlyWiki

Hello all,

Using Nico's projectify with the excellent quick todo add, has put me in mind for something similar.

I'd like to have a tiddler with an edit box visible in view mode, and when I type something in that edit box and press enter, what I've typed gets appended to a tiddler (as I understand, cant be the tiddler Im using the edit box in), with a timestamp.

I know this will involve a keyboard widget. While I was trying it out myself, I got stuck trying to append.

Has anyone done anything similar and/or willing to help?

Thanks!
Diego


Mat

unread,
Mar 20, 2021, 3:12:18 PM3/20/21
to TiddlyWiki
Hi Diego. 
Lot of ambiguous points in your post, but I think it should be pretty simple once it is clear what you want:

What do you mean with "gets appended to a tiddler" - where? To the tiddlers title? To the bottom of the tiddler? And yes it can, without a problem, "be appended" to the current tiddler. And should the timestamp be part of the string you append?

And what do you mean that you "know it will involve a keyboard widget" - are you saying you want it to? (It certainly doesn't have to). And what do you mean that the keyboardwidget would do?

<:-)

Saq Imtiaz

unread,
Mar 20, 2021, 4:07:57 PM3/20/21
to TiddlyWiki
@Diego, this is untested code but should hopefully point you in the right direction:

\define appendBoxActions()
<$action-setfield $tiddler=<<targetTiddler>> text={{{ [<targetTiddler>get[text]addsuffix<linebreak>addsuffix<linebreak>addsuffix{$:/temp/appendbox}] }}}/>
<$action-setfield $tiddler="$:/temp/appendbox" text=""/>
\end

<$vars targetTiddler="Target" linebreak="
">
<$keyboard key="Enter" actions=<<appendBoxActions>>>
<$edit-text tag="textarea" placeholder="" tiddler="$:/temp/appendbox"/>
</$keyboard>
</$vars>

Since you are only appending on the Enter key as opposed to on every keystroke, you could indeed apply this code via a viewtemplate and append to the tiddler the textarea field is in, if so desired. The key is that the edit-text widget writes to a temp tiddler.


On Saturday, March 20, 2021 at 8:02:54 PM UTC+1 dieg...@gmail.com wrote:

Mohammad Rahmani

unread,
Mar 21, 2021, 12:51:59 AM3/21/21
to tiddl...@googlegroups.com
Lovely solution Saq!

why it does not work with a non-existent Target tiddler? how can I extend the code to address this issue?


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a011af6d-89a5-4d90-bbf6-df25fc88f434n%40googlegroups.com.

Saq Imtiaz

unread,
Mar 21, 2021, 4:44:55 AM3/21/21
to TiddlyWiki
Try adding an else[] after <targetTiddler>get[text]

Mohammad Rahmani

unread,
Mar 21, 2021, 6:44:51 AM3/21/21
to tiddl...@googlegroups.com
Saq
Thank you! works like a charm!
Would you please explain what empty else[] does here?




Best wishes
Mohammad


Saq Imtiaz

unread,
Mar 21, 2021, 8:31:08 AM3/21/21
to TiddlyWiki
@Mohammad the underyling issue is one that I think we have discussed before in another context.

TiddlyWiki filters distinguish between no results from a filter step, and an empty string as a result.

When there is no result from a filter step, like with get[text] on a non-existent tiddler, the next filter step receives no input and therefore the entire filter run will have no output. However, by using else[] we specify an empty string as the input to the next step if the previous step had returned no result. This allows the addsuffix[] step to return a result.

This is the same reason why we have the is[blank] operator, to distinguish between no result, and an empty string as a result.

Mohammad Rahmani

unread,
Mar 21, 2021, 10:14:15 AM3/21/21
to tiddl...@googlegroups.com
Hi Saq,
Many thanks for clarification
So the magic is the empty string returned by else[]

Thanks again!


dieg...@gmail.com

unread,
Mar 21, 2021, 2:57:47 PM3/21/21
to TiddlyWiki
@Mat: You're right - I typed out a question but left most of the context in my head! Apologies! Saq guessed what I wanted.

@Saq: Thank you for the code and the explanation of the else! 

It might be worth adding that note about blank vs empty string as inputs to the next step in the filters documentation.
Reply all
Reply to author
Forward
0 new messages