How do I interact with my own <$edit-text> widget?

I want to be able to use <$edit-text> widget or a <textarea> and interact with it from a button.

Something like this:

<$edit-text/>

<$button>
<!-- do stuff with edit text widget -->
</$button>

The button would copy each line of text into fields. The fields would have the same prefix plus a number.

1 Like

To interact with the content of an edit-text widget, you need to use toolbar buttons from within the editor that invoke the widget message tm-edit-text-operation:
https://tiddlywiki.com/#WidgetMessage%3A%20tm-edit-text-operation

For an example see the core editor template:

Could you not also assign a field for the edit-text widget, and then process the value of the field?

If the intent is to process the text entered in the edit-text widget then that approach is entirely feasible and would be a good way to approach it.

If however you want to transform the text and continue editing, it will be considerably more performant to work with text operations, which also allow the ability to undo changes.

I would like the ability to paste lines of text in the <textarea> and then transfer that into the fields.

For example:

<textarea>
line 1
line 2
line 3 
line 4
line 5
</textarea>

Then line-by-line gets converted into a field with a push of a button.

field-1: line 1
field-2: line 2
field-3: line 3
field 4: line 4
field 5: line 5

Untested code follows, adjust tiddler titles as needed.

Using action-setfield:


<$edit-text tiddler="$:/temp/my-text" class="tc-edit-texteditor" placeholder="paste here..."/>

<$button actions="""
	<$list filter="[{$:/temp/my-text}splitregexp[\n]]" counter="counter">
		<$action-setfield $tiddler="target" $field={{{ [[field-]addsuffix<counter>] }}} $value=<<currentTiddler>>/>
	</$list>
""">create fields</$button>

Using action-setmultiplefields:


<$edit-text tiddler="$:/temp/my-text" class="tc-edit-texteditor" placeholder="paste here..."/>

<$button actions="""
	<$action-setmultiplefields
		$tiddler="target"
		$fields={{{ [{$:/temp/my-text}splitregexp[\n]count[]] :map[range[1],<currentTiddler>addprefix[fields-]join[ ]] }}}
		$values={{{ [{$:/temp/my-text}splitregexp[\n]format:titlelist[]join[ ]] }}}
	/>
""">create fields</$button>
1 Like

This works, I simply put the code directly in the $:/core/ui/EditTemplate/fieldsso that it’s always there when I am editing tiddlers. Then just change “target” to “<<currentTiddler>>”. Thanks.

1 Like