Create tiddler from textfield/dropdown,etc and adding prefix to tiddler name

Hi and merry christmas.

Right before christmas i managed to google some things together. my goal is a tiddler with some form elements (textarea, dropdown,etc) and a button who creates tiddlers (and fills custom fields of that tiddler) based on the input of the form.

so far i have this, but i don´t now how to manage that all the tiddler name which will be created based on the “name_temp” field, gets a “_table” concencated at the end of the name_temp field

<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='name_temp' placeholder='table:'/>
<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='label' placeholder='Label'/>
<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='url' placeholder='url'/>
<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='text' placeholder='Links and stuff'/>

<$button>Create Tiddler
<$action-setfield $tiddler={{$:/state/NewTiddlerForm!!name_temp}}
label={{$:/state/NewTiddlerForm!!label}}
url={{$:/state/NewTiddlerForm!!url}}
text={{$:/state/NewTiddlerForm!!text}}
tags=“table”
/>

<$action-navigate $to={{$:/state/NewTiddlerForm!!name_temp}}/>
<$action-setfield $tiddler=’$:/state/NewTiddlerForm’ name_temp=’’ text=’’ description=’’ tags=’’/>
</$button>

<$button>Clear Form
<$action-setfield $tiddler=’$:/state/NewTiddlerForm’ name_temp=’’ text=’’ description=’’ tags=’’/>
</$button>
</$wikify>

basically i want a “tiddler-factory” tiddler recipe, where i can create tiddlers, their tags and their custom fields based on a form

Something like this should work –

<$action-setfield $tiddler={{{[{$:/state/NewTiddlerForm!!name_temp}}addsuffix[_table]]}}} ...

You will have to make corresponding changes in the setfield and navigate widgets.

Mark S wrote:

<$action-setfield $tiddler={{{[{$:/state/NewTiddlerForm!!name_temp}}addsuffix[_table]]}}} ...

There’s a small syntax error in Mark’s reply… an extra “}”… it should be:
<$action-setfield $tiddler={{{ [{$:/state/NewTiddlerForm!!name_temp}addsuffix[_table]] }}} ...

There also seems to be an unneeded </$wikify>at the end of your posted code.

Here’s my suggested “cleanup” of your code:

\define form() $:/state/NewTiddlerForm

<$edit-text class='tc-edit-texteditor' tiddler=<<form>> field='name_temp' placeholder='Table'/>
<$edit-text class='tc-edit-texteditor' tiddler=<<form>> field='label' placeholder='Label'/>
<$edit-text class='tc-edit-texteditor' tiddler=<<form>> field='url' placeholder='URL'/>
<$edit-text class='tc-edit-texteditor' tiddler=<<form>> field='text' default="" placeholder='Links and stuff'/>

<$button>Create Tiddler
   <$tiddler tiddler=<<form>>>
      <$action-createtiddler $basetitle={{{ [{!!name_temp}addsuffix[_table]] }}}
         label={{!!label}} url={{!!url}} text={{!!text}} tags="table">
         <$action-navigate $to=<<createTiddler-title>>/>
      </$action-createtiddler>
   </$tiddler>
   <$action-deletetiddler $tiddler=<<form>>/>
</$button>
<$button>Clear Form
   <$action-deletetiddler $tiddler=<<form>>/>
</$button>

Notes:

  1. Use a macro (e.g. \define form() ...) to set a variable containing the title of the input tiddler (i.e., $:/state/NewTiddlerForm). This allows you to refer to <<form>> instead of hard-coding the input tiddler’s title in multiple places. This makes your code more compact and more readable, and also makes it easier to change the input tiddler’s title later on if you want/need to.

  2. Use $action-createtiddler instead of $action-setfield, so that if you enter the same title more than once, it will automatically add a number suffix to the resulting tiddler title (i.e., foo_table, foo_table 1, foo_table 3, etc.).

  3. Enclose the $action-createtiddler within a $tiddler widget so that the field references don’t need to include the form tiddler title (i.e., just {{!!label}}, {{!!url}}, etc.)

  4. Using $action-createtiddler also enables reference to <<createTiddler-title>> inside the widget to navigate to the newly created tiddler title.

  5. Use $action-deletetiddler instead of $action-setfield to reset the form inputs. This will completely remove the $:/state/NewTiddlerForm, so that the inputs revert to showing their placeholder values, instead of being empty.

enjoy,
-e

2 Likes

well thank you @EricShulman that code seems more like it and it also fits my requirement.

i barely understand half of what the code does, but for me it is a good point of refernce to untanngle it bit by bit to get a more thorough understanding of the tiddlywiki concept (coming from python and javascript)

@EricShulman one small addition.

how can i add a tag, which contains a space ?

  <$action-createtiddler $basetitle={{{ [{!!name_temp}addsuffix[_table]] }}}
     label={{!!label}} url={{!!url}} text={{!!text}} tags="tagname with spaces"> doesnt work

Edit: I can answer my own question, found the solution here: Escape SPACE in wiki/ html

Wrap multi-word tags in `[[]]`

tags="[[Personal Contact]] tag2"