Input Prompts to Provide Variables With Button?

345 views
Skip to first unread message

Darth Mole

unread,
Jun 8, 2021, 9:42:53 PM6/8/21
to TiddlyWiki
Hello,

I hope I didn't miss a clear answer for this but is there anyway to prompt the user for a variable, with an input field, after a button press?

I found the below code to combine multiple tiddlers into one based on a shared tag, and then modified it to add a tag.

\define join(label,tag,target,targettag)
<$button> $label$
   <$wikify name="out" text="""<$list filter="[tag[$tag$]]"><$text text={{!!text}}/></$list>""">
      <$action-setfield $tiddler="$target$" text=<<out>> tags=<<targettag>> />
   </$wikify>
</$button>
\end

<<join "Create Chapter" "Book 1 Chapter 1" "Book 1 Chapter 1" "Book 1" >>

As of now the variables for the button are set by the <<join line above which has to be manually set.

My question/hope is if there is a way to prompt the user to input the variables, one at a time, via an input box/field/prompt, that would allow them to set the variables each time the button is pressed.

Thank you!

Charlie Veniot

unread,
Jun 8, 2021, 10:15:31 PM6/8/21
to TiddlyWiki
Instead of press buttons, then prompt user for variable values via fields, would you be open to a flow change, i.e.:

  1. Prompt user for values via fields
  2. Press button?

Darth Mole

unread,
Jun 8, 2021, 10:26:15 PM6/8/21
to TiddlyWiki
Nope, not opposed to it. Just trying to simplify/automate the process of combining individual tiddlers instead of manually editing the Tiddler each time.

The flow isn't set in stone!

Charlie Veniot

unread,
Jun 8, 2021, 10:33:26 PM6/8/21
to TiddlyWiki
Snippet of alternative code heading over in about 15 minutes !

Charlie Veniot

unread,
Jun 8, 2021, 10:39:55 PM6/8/21
to TiddlyWiki
I can't really properly test this, but maybe this does the trick?

<$vars dataTiddler={{{ [<currentTiddler>addsuffix[ Data]] }}}>

<fieldset>
    <legend>Whatever description needs to be put here:</legend>

<table>
<tr><td>Label:</td>
<td> <$edit-text tiddler={{{ [<dataTiddler>] }}} field="my_label"/> </td></tr>
<tr><td>Tag:</td>
<td> <$edit-text tiddler={{{ [<dataTiddler>] }}} field="my_tag"/> </td></tr>
<tr><td>Target:</td>
<td> <$edit-text tiddler={{{ [<dataTiddler>] }}} field="my_target"/> </td></tr>
<tr><td>Targetting:</td>
<td> <$edit-text tiddler={{{ [<dataTiddler>] }}} field="my_targetting"/> 
</td></tr>
</table>

<$vars myLabel={{{ [<dataTiddler>get[my_label]] }}}
              myTag={{{ [<dataTiddler>get[my_tag]] }}}
              myTarget={{{ [<dataTiddler>get[my_target]] }}}
              myTargetting={{{ [<dataTiddler>get[my_targetting]] }}}>
<$button> Create <<myLabel>>
   <$wikify name="out" text="""<$list filter="[tag<myTag>]"><$text text={{!!text}}/></$list>""">
      <$action-setfield $tiddler=<<myTarget>> text=<<out>> tags=<<myTargetting>> />
   </$wikify>
</$button>
</$vars>

  </fieldset>

</$vars>

On Tuesday, June 8, 2021 at 10:42:53 PM UTC-3 iamdar...@gmail.com wrote:

Darth Mole

unread,
Jun 8, 2021, 10:52:43 PM6/8/21
to TiddlyWiki
You are awesome! Thank you very much! It works just great! Thank you, thank you, thank you, thank you!

Charlie Veniot

unread,
Jun 8, 2021, 11:21:19 PM6/8/21
to TiddlyWiki
Hey, my pleasure.  Although I'm often too deeply immersed in my own projects, I do find it hard to pass up quick and fun "programming" opportunities.

If ever you need to tweak that somehow, just post right back into this thread.

There are often many different ways of doing things, and I just went ahead with the fastest solution I could think of.  Well, I did roll up my sleeves a smidgen to make it look kind of pretty with some HTML.  Although I'm more into practical than pretty, ain't nothing wrong with pretty.  Well, the rendering is kind of pretty.  The HTML, maybe not so much ...

Rock'n roll !

Eric Shulman

unread,
Jun 9, 2021, 1:09:25 AM6/9/21
to TiddlyWiki
On Tuesday, June 8, 2021 at 8:21:19 PM UTC-7 cj.v...@gmail.com wrote:
There are often many different ways of doing things, and I just went ahead with the fastest solution I could think of...

Here's a much more compact way to write the same functionality:
\define temp() $:/temp/input/$(currentTiddler)$

|      Label:|<$edit-text tiddler=<<temp>> field="label"/>    |
|   From Tag:|<$edit-text tiddler=<<temp>> field="fromtag"/>  |
|     Target:|<$edit-text tiddler=<<temp>> field="target"/>   |
| Target Tag:|<$edit-text tiddler=<<temp>> field="targettag"/>|

<$tiddler tiddler=<<temp>>>
<$button> <$view field="label">join tiddlers</$view> 
   <$action-setfield $tiddler={{!!target}} text={{{ [tag{!!fromtag}get[text]join[]] }}} tags={{!!targettag}} />
   <$action-deletetiddler tiddler=<<temp>> />
</$button>
</$tiddler>

Notes:
1) the inputs are stored in a $:/temp tiddler, so it doesn't clutter up the visible list of tiddlers
2) the temp tiddler's title is assembled using a simple \define, rather than using $vars with filtered transclusion syntax
3) the input form uses simple wikitext table syntax instead of HTML syntax to produce more readable code
4) the $edit-text widgets target <<temp>> rather than the more verbose, but equivalent, {{{ [<temp>] }}}
5) the $button is enclosed in a $tiddler widget so that references to the input field values can use {{!!fieldname}}
6) the $button uses <$view>...</$view> to provide a default label if none is input
7) instead of using $wikify, the output text is constructed using filtered transclusion syntax to join the source tiddler content into a single string
8) the $:/temp tiddler is deleted after processing the $button press to clear all the form inputs for re-use

enjoy,
-e

Darth Mole

unread,
Jun 9, 2021, 1:49:07 AM6/9/21
to TiddlyWiki
Hello and thank you very much for providing another solution! I very much appreciate the answers and also the information provided!

As a quick follow-up question:

For both methods: 

<$action-setfield $tiddler=<<myTarget>>
<$action-setfield $tiddler={{!!target}}

If I wanted to add/append some static text to the end of the target field value, how would I do so? I have tried various ways, using + or enclosing the variable and text in " or brackets but can't seem to find the combination.

For an idea:

Target = HTVW

<$action-setfield $tiddler=[<<myTarget>> Chapter 01] would produce a Tiddler with the title of HTVW Chapter 01
<$action-setfield $tiddler={{{!!target}}+ Chapter 01} would produce a Tiddler with the title of HTVW Chapter 01

Thank you again for your help and any additional information/solutions you can provide!

Eric Shulman

unread,
Jun 9, 2021, 2:37:26 AM6/9/21
to TiddlyWiki
On Tuesday, June 8, 2021 at 10:49:07 PM UTC-7 iamdar...@gmail.com wrote:
If I wanted to add/append some static text to the end of the target field value, how would I do so?

Using filtered transclusion:
<$action-setfield $tiddler={{{ [{!!target}addsuffix[ Chapter 01]] }}} etc.

if you want, you could add the suffix to the input table:
|     Target suffix:|<$edit-text tiddler=<<temp>> field="suffix"/>   |

and then you would use:
<$action-setfield $tiddler={{{ [{!!target}addsuffix{!!suffix}] }}} etc.

enjoy,
-e

Darth Mole

unread,
Jun 9, 2021, 12:53:36 PM6/9/21
to TiddlyWiki
Thank you very much! It worked like a charm! 

I'm also really sorry to ask yet another question but for some reason the solution isn't clicking just yet. I've been searching all morning trying to find the right combination/solution and while I have made a little progress I think I'm mixing too many functions together. The below code is slightly modified from the original one above due to having a different but related purpose.

 \define temp() $:/temp/input/$(currentTiddler)$

|      Story Name:|<$edit-text tiddler=<<temp>> field="storyname"/>    |
|   Story Abbreviation:|<$edit-text tiddler=<<temp>> field="storyabbrev"/>  |

<$tiddler tiddler=<<temp>>>
<$button> Create Story
   <$action-setfield $tiddler={{!!storyabbrev}} text={{!!tocscript}} tags=Stories />
   <$action-setfield $tiddler={{{ [{!!storyabbrev}addsuffix[ Chapter 001]] }}} tags={{!!storyabbrev}} />
   <$action-deletetiddler tiddler=<<temp>> />
</$button>
</$tiddler>

<div class="tc-table-of-contents">

<<toc-selective-expandable "{{!!storyabbrev}}" "sort[title]">>

</div>

I can't figure out how to:

1) Make the toc div text a variable, named toscript, to call it in the script like the fields, so I can add it to the new tiddler being created.
2) Update the tag name in the toc-selective-expandable macro before it is added to the new tiddler being created.

Every time I try to use /define or $set I either break the existing code or <<tocscript>> {{!!tocscript}} $tocscript$ (can't figure out which one, if any, to use) doesn't "activate"

I was also thinking of trying to use an existing tiddler to act as the template for the toc div text but I ran into issues with that as well.

Thanks again and once again my apologies if these are simple questions.

Eric Shulman

unread,
Jun 9, 2021, 2:05:23 PM6/9/21
to TiddlyWiki
On Wednesday, June 9, 2021 at 9:53:36 AM UTC-7 iamdar...@gmail.com wrote:
I can't figure out how to:
1) Make the toc div text a variable, named tocscript, to call it in the script like the fields, so I can add it to the new tiddler being created.

Move the toc div text into a macro named "tocscript".  Macros are essentially variables that can accept parameters.

2) Update the tag name in the toc-selective-expandable macro before it is added to the new tiddler being created.

Within a macro, there are two forms of syntax that are automatically replaced when the macro is processed:
* instances of $paramname$ are replaced by corresponding values that are passed to the macro as parameters
* instances of $(varname)$ are replaced by corresponding values that are defined in variables before the macro is invoked

Thus, for your purposes:
\define temp() $:/temp/input/$(currentTiddler)$

\define tocscript()
<div class="tc-table-of-contents">
<<toc-selective-expandable "$(storyabbrev)$" "sort[title]">>
</div>
\end

|      Story Name:|<$edit-text tiddler=<<temp>> field="storyname"/>    |
|   Story Abbreviation:|<$edit-text tiddler=<<temp>> field="storyabbrev"/>  |

<$tiddler tiddler=<<temp>>>
<$button> Create Story
   <$vars storyabbrev={{!!storyabbrev}}>
   <$action-setfield $tiddler={{!!storyabbrev}} text=<<tocscript>> tags="Stories" />
   <$action-setfield $tiddler={{{ [{!!storyabbrev}addsuffix[ Chapter 001]] }}} tags={{!!storyabbrev}} />
   <$action-deletetiddler tiddler=<<temp>> />
   </$vars>
</$button>
</$tiddler>
 
Notes:
* The $vars widget fetches the !!storyabbrev input value to turn it into a variable named "storyabbrev", so that it can then be automatically replaced in the tocscript macro
* I don't see anywhere that you actually use the "!!storyname" input value

enjoy,
-e

Darth Mole

unread,
Jun 9, 2021, 2:37:15 PM6/9/21
to TiddlyWiki
Thank you so much Eric! Really thank you so much! I'm a little happy to see I was kind of heading in the right direction at one point earlier, except I put the \end of the tocscript define below the </$tiddler> because I was afraid it wouldn't include itself in the button code and it broke it lol. Also thank you very much for providing the explanations as well! 

The !!storyname was actually left over from the step before this one. I hadn't considered having a dynamic toc at first. Though now I'll use it in the tocscript to help identify the page a bit better. Thank you for looking that closely at the script!

TW Tones

unread,
Jun 9, 2021, 7:02:00 PM6/9/21
to TiddlyWiki
iamdar,

Here is a link to some documentation that may help you more generally at this phase of your learing, https://anthonymuscio.github.io/#Standard%20Nomenclature

Its an updated version of something published by Tobias in the past. In particular look at the foot notes about values in parameters widget and HTML, it shows why any "concatenation" to make compound values needs to be done, as ewrioc says the best way without making custom macros and wikifying them is to use the filtered transclusions.  With these you use a filter inside triple curly braces to generate the value (no need for an intermediate variable) and filters permit variables, transclusions and field content to be concatinated.

Also, As someone in the learning phase please do feedback if you need something clarified or added to my document as you have the insight to what is needed during the learning process, unfortunately I now know too much. You can help other that pass this way in the future.

Regards
Tones

Darth Mole

unread,
Jun 9, 2021, 8:57:30 PM6/9/21
to TiddlyWiki
Hello and thank you very much! I'll take a look and provide any feedback I can.

It seems my biggest issue is not having examples that allow me to confirm what I'm thinking with what I read. Or at least not having them where I think they should be based on where I'm looking inside TiddlyWiki.

IE:

When trying to find the define solution for the toc code above I searched the following Tiddlers for a matching example.


Now, after receiving the help from earlier, when I went back and looked at the tiddlers in question I noticed this:

\define dumpvariables()
<ul>
<$list filter="[variables[]]" variable="varname">
<li>
<strong><code><$text text=<<varname>>/></code></strong>:<br/>
<$codeblock code={{{ [<varname>getvariable[]] }}}/>
</li>
</$list>
</ul>
\end

and also 

Several of the examples on https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText that also nearly match the code provided above in the replies. 

However, for some reason (probably on my side of things) the above example and

\define sayhi(name:"Bugs Bunny" address:"Rabbit Hole Hill")
 Hi, I'm $name$ and I live in $address$. 
\end

Didn't seem to be the same to me. In fact, the only reason I was able to finally figure out the following was because I knew it should work like the code given so it was just a matter of process of elimination. Until a few minutes ago, and only because I knew the example worked, as well as the code given above for me to consider, was I finally able to see where they got "Bugs" from i the output.

\define say-hi-using-variables() 
Hi, I'm $(name)$ and I live in $(address)$. 
\end 

 \define name() Bugs

<$set name="address" value="Rabbit Hole Hill"> 
<<say-hi-using-variables>>
 </$set>

Hi, I'm Bugs and I live in Rabbit Hole Hill.

Long story short, I may just represent an outlier scenario and if that is the case I apologize in advance for any easy questions. Of course, I will still read over everything and will be sure to ask questions!
Reply all
Reply to author
Forward
0 new messages