On Thursday, July 2, 2020 at 8:18:46 AM UTC-7, Jake wrote:
>
> From EditTextWidget:
>> "One trap to be aware of is that the edit text widget cannot be used to 
>> edit a field of the tiddler that contains it. Each keypress results in the 
>> tiddler being re-rendered, which loses the cursor position within the text 
>> field."
>>
>
Here's a macro that provides a work-around interface:
\define input(fieldname)
<$vars
   temp="$:/temp/$(currentTiddler)$/$fieldname$"
   default={{{ [<currentTiddler>get[$fieldname$]] }}}
   placeholder="enter a value for $fieldname$">
<$keyboard key="enter" actions="""
   <$action-setfield $tiddler=<<currentTiddler>> $field="$fieldname$" 
$value={{{ [<temp>get[text]] }}} />
   <$action-deletetiddler $filter="[<temp>]" />
""">
<$edit-text tag="input" tiddler=<<temp>> default=<<default>> placeholder=<<
placeholder>>/>
</$keyboard>
<$button tooltip="delete field"> {{$:/core/images/delete-button}}
   <$action-deletefield $tiddler=<<currentTiddler>> $field="$fieldname$"/>
   <$action-deletetiddler $filter="[<temp>]" />
</$button>
<$button tooltip="cancel input"> {{$:/core/images/cancel-button}}
   <$action-deletetiddler $filter="[<temp>]" />
</$button>
<$button tooltip="save input"> {{$:/core/images/done-button}}
   <$action-setfield $tiddler=<<currentTiddler>> $field="$fieldname$" $value
={{{ [<temp>get[text]] }}} />
   <$action-deletetiddler $filter="[<temp>]" />
</$button>
</$vars>
\end

How to use it:
* copy the above code into a tiddler (e.g., 
"$:/TiddlyTools/Macros/getinput")
* tag that tiddler with "$:/tags/Macro"
* in any other tiddler, write:
<<input "foo">>

How it works:
* the $edit-text default value is the current value in "SomeField" of 
"SomeTiddler"
* the $edit-text input goes into a temporary tiddler named 
$:/temp/SomeTiddler/SomeField
* the "delete" button removes "SomeField" from "SomeTiddler"
* the "cancel" button discards the temporary tiddler (automatically 
reverting the input contents to showing the default value)
* the "ok" button copies the temporary tiddler content to "SomeField" in 
"SomeTiddler"
* the "enter" key is a shortcut for pressing "ok"

I'm also working on an enhanced version where the buttons appear as a 
"popup"
only when the $edit-text control gets the input focus, but I'm still 
debugging that
version (there's a strange interaction between the focus and the popup that 
I
haven't yet figured out).

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/21d1aacb-a973-465e-bb94-1cb5f507138do%40googlegroups.com.

Reply via email to