On Monday, June 21, 2021 at 1:19:40 AM UTC-7 [email protected] wrote:

> How can I make an html form in a tiddler, and save the values entered in 
> the form, into a data tiddler? 
>

To store the input in a field, you will need to use the $edit-text widget, 
like this:
<$edit-text field="somefield" tag="textarea" class="tc-edit-texteditor"/>

*Unfortunately, this won't work quite right. * The problem is that as you 
type each character of input, the TWCore refresh handling will be triggered 
for the current tiddler which will, in turn, cause the $edit-text widget to 
be re-rendered and, as a side effect, the widget will lose the input 
focus.  The result is that you can only type one character at a time, and 
then you will have to click inside the textarea to restore the focus.  This 
is, of course, completely impractical.

However, there is a way to work around this by using a temporary tiddler to 
hold the $edit-text input *while you type*, and then press a $button to 
copy that input into the desired field of the current tiddler.  Try 
something like this:
\define temp() $:/temp/$(currentTiddler)$/somefield

<$edit-text tiddler=<<temp>> tag="textarea" class="tc-edit-texteditor" 
default={{!!somefield}}/>
<$button> ok
   <$action-setfield somefield={{{ [<temp>get[text]else{!!somefield}] }}}/>
   <$action-deletetiddler $tiddler=<<temp>> />
</$button>
<$button> cancel
   <$action-deletetiddler $tiddler=<<temp>> />
</$button>

Notes:
* temp() defines a temporary tiddler that includes the name of the current 
tiddler and the name of the target field
* the $edit-text gets it's starting value from "somefield" of the current 
tiddler and then, as you type, it stores the changed value in the $:/temp 
tiddler
* the "ok" button then copies the value from the $:/temp tiddler back into 
"somefield" of the current tiddler
* note that, if you haven't actually changed the contents of the $edit-text 
field, the "ok" button simply copies the previously stored value from 
"somefield" (i.e., no change in value occurs)
* the "ok" button also deletes the $:/temp tiddler so the value in the 
$edit-text widget will now show the new "default" value from "somefield" of 
the current tiddler
* an optional "cancel" button deletes the $:/temp tiddler so the value 
shown in the $edit-text automatically reverts to the previously stored 
value from "somefield" of the current tiddler

enjoy,
-e 

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/031979a3-82b9-46eb-90e1-7ba24059888fn%40googlegroups.com.

Reply via email to