Keyboard Widget Issue

74 views
Skip to first unread message

Stobot

unread,
Jul 27, 2020, 1:59:53 PM7/27/20
to TiddlyWiki
I'm running into what seems to be a scope issue and not sure how to work around it. I'm hoping that some experts here might see what I'm doing wrong.

I have an edit-text widget for the user to enter a new title name, and then I need to append a date to the end of it and create a new tiddler for it. I can have that work with the button no problem, but can't figure out how to add they keyboard shortcut properly.

This works from a button standpoint:

\define newtiddlername() $(mytitle)$ $(now)$
\define addnewtiddler() <$action-createtiddler $basetitle=<<newtiddlername>>/>

<$edit-text tiddler="$:/temp/mytitle" tag="input" default=""/>
<$vars mytitle={{$:/temp/mytitle}}>
<$button actions=<<addnewtiddler>>>
Add
</$button>
</$vars>

but this doesn't work

\define newtiddlername() $(mytitle)$ $(now)$
\define addnewtiddler() <$action-createtiddler $basetitle=<<newtiddlername>>/>

<$keyboard key="enter" actions=<<addnewtiddler>>>
<$edit-text tiddler="$:/temp/mytitle" tag="input" default=""/>
<$vars mytitle={{$:/temp/mytitle}}>
<$button actions=<<addnewtiddler>>>
Add
</$button>
</$vars>
</$keyboard>

I tried moving the vars outside of the keyboard, but then each character typed makes the input box lose focus...

Ideas?

JD

unread,
Jul 28, 2020, 12:20:39 PM7/28/20
to TiddlyWiki
Hi Stobot! Have you found a solution? 


This works for me...
\define newtiddlername() $(mytitle)$ $(now)$
\define addnewtiddler() <$vars mytitle={{$:/temp/mytitle}}><$action-createtiddler $basetitle=<<newtiddlername>>/></$vars>

<$keyboard key="enter" actions=<<addnewtiddler>>>
<$edit-text tiddler="$:/temp/mytitle" tag="input" default=""/>
<$button actions=<<addnewtiddler>>>
Add
</$button>
</$keyboard>

That is, moving <$vars> widget to nearest possible place where it will be used...


With these previous code....
<$keyboard key="enter" actions=<<addnewtiddler>>>
<$edit-text tiddler="$:/temp/mytitle" tag="input" default=""/>
<$vars mytitle={{$:/temp/mytitle}}>
<$button actions=<
<addnewtiddler>>>
Add
</$button>
</$vars>
</$keyboard>

The button will use the <<mytitle>> that is already declared... While the keyboard is trying to use the same variable -- however, it's not declared yet "above" it!

But! moving <$vars> "above" <$keyboard> means that with every key press, <$vars> has to recompute (don't know the exact terms / mechanism here), refreshing its contents, taking away the focus from all inside it, including <$text-edit>... 

So, moving <$vars> inside <<addnewtiddler>> means that as long as <<addnewtiddler>> isn't being ran, <<mytitle>> won't recompute, won't refresh that part of the DOM 

Hopefully someone can explain all these better for me lol ! I am so bad at this

-jd

Stobot

unread,
Jul 28, 2020, 1:05:12 PM7/28/20
to TiddlyWiki
Aha! I hoped it was going to be simple - thanks for chiming in JD! That's exactly what I needed - and the logic makes sense.

On a separate note, stupid question - how did you generate the "code block" in your reply? With the change to Google Groups format, I don't see any way to do that anymore.

JD

unread,
Jul 28, 2020, 2:04:09 PM7/28/20
to TiddlyWiki
On long macros with loops, those kind of things (forgetting where I've declared variables and such) happen a lot! I've learned to keep a close eye on them... Had hard lessons learned with variables! haha!

Oh my, I haven't changed to the new GoogleGroups look, can't help you with that! Now I'm afraid to update lol
Reply all
Reply to author
Forward
0 new messages