How to send message using checkbox widget?

47 views
Skip to first unread message

LinOnetwo

unread,
Dec 24, 2019, 10:45:17 AM12/24/19
to TiddlyWikiDev
I try to use following checkbox, I want the state be sync to my plugin.

<$checkbox checkactions="checkUseServerStoryList" uncheckactions="unCheckUseServerStoryList" >
 <$action-sendmessage $name="checkUseServerStoryList" $message="tm-solid-useServerStoryList" />
 <$action-sendmessage $name="unCheckUseServerStoryList" $message="tm-solid-notUseServerStoryList" />
 <<lingo UseServerStoryList>>
</$checkbox>

In my plugin I receive that message:

    // sync config to here
   $tw.rootWidget.addEventListener('tm-solid-useServerStoryList', () => {
     this.useServerStoryList = true;
     console.log(this.useServerStoryList);
     
   });
   $tw.rootWidget.addEventListener('tm-solid-notUseServerStoryList', () => {
     this.useServerStoryList = false;
     console.log(this.useServerStoryList);
   });
在此输入代码...
But nothing is log out, that is why?

Eric Shulman

unread,
Dec 24, 2019, 11:36:37 AM12/24/19
to TiddlyWikiDev
On Tuesday, December 24, 2019 at 7:45:17 AM UTC-8, LinOnetwo wrote:
I try to use following checkbox, I want the state be sync to my plugin.
<$checkbox checkactions="checkUseServerStoryList" uncheckactions="unCheckUseServerStoryList" >
 <$action-sendmessage $name="checkUseServerStoryList" $message="tm-solid-useServerStoryList" />
 <$action-sendmessage $name="unCheckUseServerStoryList" $message="tm-solid-notUseServerStoryList" />
 <<lingo UseServerStoryList>>
</$checkbox>


That is not the correct way to invoke actions from widgets.  $action-sendmessage widget does not recognize or use a $name parameter.

Rather, you must use the "\define" syntax to declare the actions as macros to give them names.  Place the following at the start of the tiddler:
\define checkUseServerStoryList()
   <$action-sendmessage $message="tm-solid-useServerStoryList" />
\end

\define uncheckUserServerStoryList()
   
<$action-sendmessage $message="tm-solid-notUseServerStoryList" />
\end

Then, in your checkbox widget, you would write:
<$checkbox checkactions=<<checkUseServerStoryList>> uncheckactions=<<unCheckUseServerStoryList>
> >
  <
<lingo UseServerStoryList>>
</$checkbox>

Alternatively, if you prefer to have the checkbox AND actions written together, you can forego the use of names altogether, and place the actions in-line, within the checkbox syntax, like this:
<$checkbox
    checkactions="""<$action-sendmessage $message="tm-solid-useServerStoryList"    />"""
  uncheckactions="""<$action-sendmessage $message="tm-solid-notUseServerStoryList" />""" >
  <
<lingo UseServerStoryList>>
</$checkbox>
Note that, because the action-sendmessage widget uses double-quotes around the $message parameter, you must use TRIPLED double-quotes surrounding the checkactions and uncheckactions parameters of the checkbox widget.

The first syntax (using \define) is recommended.

That should do it.   Let me know how it goes...

enjoy,
-e
Eric Shulman

LinOnetwo

unread,
Dec 24, 2019, 9:11:48 PM12/24/19
to TiddlyWikiDev
That works, Thank you, Eric!

And I chage to dash saparated variable, to fit wikitext:

\define check-use-server-story-list()
 <$action-sendmessage $message="tm-solid-use-server-story-list" />
\end

\define uncheck-use-server-story-list()
 <$action-sendmessage $message="tm-solid-not-use-server-story-list" />
\end


<$checkbox field="use-server-story-list" checked="yes" unchecked="no" default="yes" checkactions=<<check-use-server-story-list>> uncheckactions=<<uncheck-use-server-story-list>> >
<<lingo UseServerStoryList>>
</$checkbox>



在 2019年12月25日星期三 UTC+8上午12:36:37,Eric Shulman写道:

Eric Shulman

unread,
Dec 26, 2019, 10:16:57 AM12/26/19
to TiddlyWikiDev
On Tuesday, December 24, 2019 at 6:11:48 PM UTC-8, LinOnetwo wrote:
That works, Thank you, Eric!
And I change to dash separated variable, to fit wikitext:

I generally use mixed-case naming for variables and macro names, so that they don't look like message IDs.
Though in this particular case, since the macros are basically wrappers around $send-message calls,
it may be appropriate to use dash-separated naming as you have done.

-e
Reply all
Reply to author
Forward
0 new messages