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:
-
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. -
Use
$action-createtiddlerinstead 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.). -
Enclose the
$action-createtiddlerwithin a$tiddlerwidget so that the field references don’t need to include the form tiddler title (i.e., just{{!!label}},{{!!url}}, etc.) -
Using
$action-createtiddleralso enables reference to<<createTiddler-title>>inside the widget to navigate to the newly created tiddler title. -
Use
$action-deletetiddlerinstead of$action-setfieldto 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