Clear Form Fields After Submit

85 views
Skip to first unread message

Darth Mole

unread,
Jun 21, 2021, 8:20:24 PM6/21/21
to TiddlyWiki
Hello,

Is there a command that can be included with a button to clear the form fields after the button has been hit?

In one of my previous threads it was mentioned, at least how I took it, that by deleting the temp tiddler the form would be cleared. 

However, that functionality isn't occurring and instead a full refresh of the TiddlyWiki file needs to be done before the fields clear (just closing and reopening the Tiddler isn't enough either). 

Is there another action that is required to clear the fields without a refresh? Thanks!

Code in question:

\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>




Eric Shulman

unread,
Jun 21, 2021, 9:00:23 PM6/21/21
to TiddlyWiki
On Monday, June 21, 2021 at 5:20:24 PM UTC-7 iamdar...@gmail.com wrote:
... by deleting the temp tiddler the form would be cleared... However, that functionality isn't occurring

\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>

Let's suppose the containing tiddler is named "MyForm".  Then the value of <<temp>>, as defined in the macro, will be $:/temp/input/MyForm.  However, once you use <$tiddler tiddler=<<temp>>> to surround the $button code, the value of <<temp>> within the $button code will be $:/temp/input/$:temp/input/MyForm, so the $action-deletetiddler refers to the wrong tiddler title and does nothing.

The solution is to move the <$tiddler tiddler=<<temp>>> so it only affects the $action-setfield.  Here's a button definition that will work as you intend:

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

Notes:
* The $view widget uses both tiddler=... and field=... to show the correct label text without being inside the <$tiddler tiddler=<<temp>>>
* The $action-setfield is still surrounded by the $tiddler widget, so that the field references, {{!!target}}, {!!fromtag} and {{!!targettag}} still get their values from the temp tiddler
* However, the $action-deletetiddler is no longer within the $tiddler widget, so the <<temp>> value referenced there uses the original $(currentTiddler)$ value (i.e., "MyForm") to construct the correct temp tiddler name
* Also note that the parameter for $action-deletetiddler is $tiddler=... not tiddler=...

enjoy,
-e

Darth Mole

unread,
Jun 21, 2021, 9:24:22 PM6/21/21
to TiddlyWiki
Thank you very much! Works like a charm now! Much much much appreciated!
Reply all
Reply to author
Forward
0 new messages