Edit-text widget question

I am using an edit-text widget to edit many of the fields of my railroad tiddlers (see screenshot).

The button to active the widget is just to the right of the field value and only appears on hover.

I’ve recently discovered the focus parameter of the widget and love the way it works. My question is this: is there a way to have the focus go back to the initial button activating the edit-text widget when I hit the checkmark for save? Right now, when I hit save, the focus remains in the edit text area, but the entire text the I entered is now highlighted.

Thanks in advance!

You can use the tm-focus-selector message : https://tiddlywiki.com/#WidgetMessage%3A%20tm-focus-selector

Here’s an example from the core: https://tiddlywiki.com/#%24%3A%2Fcore%2Fmacros%2Ftag-picker

Thanks for the reply. I’m not sure I understand how the example works. It doesn’t simply use the currentTiddler variable. What is the secret sauce to setting the correct parameter for tm-focus-selector? There’s a lot in that example that I don’t understand since I’ve never had the need to encounter it before.

Here’s a simpler example : https://tiddlywiki.com/#%24%3A%2Fcore%2Fui%2FAdvancedSearch%2FFilter%2FFilterButtons%2Fclear

And another one you can try :

\define focus(css)
<$action-sendmessage $message="tm-focus-selector" $param=<<__css__>> />
\end

<$button actions="""<<focus "[placeholder='input1']">>""" >input1</$button>
<$button actions="""<<focus "[placeholder='input2']">>""" >input2</$button>
<$button actions="""<<focus "[placeholder='input3']">>""" >input3</$button>


* <$edit-text placeholder="input1" field="input1"/>
* <$edit-text placeholder="input2" field="input2"/>
* <$edit-text placeholder="input3" field="input3"/>

https://demos.tiddlyhost.com/#Set%20the%20focus%20to%20an%20input

The tm-focus-selector message is sent with the action-sendmessage widget, and the param attribute takes a css selector.

You can right click > inspect to open the dev tools of your browser to see the underlying html structure of the elements on the page and know what CSS selector to use.

On my example, if you right click the text inputs :

image

As you can see, they have a placeholder attribute. You can target them with CSS with an attribute selector : [placeholder='input1'].

It might be helfpul to add a style tag in your tiddler to test your CSS selector (a macro is not necessary but this can be helpful if you need it often) :

\define testcss(css)
<style>
<<__css__>>{
border:solid 5px green;
}
</style>
\end

This way you can make sure that you are selecting the correct element, e.g :

<<testcss “[placeholder=‘input1’]”>>

If instead you use this : <<testcss “[placeholder]”>>

2 Likes

Thanks so much for the clear and concise explanation. Very much appreciated. I’ll try some things.

I ass use that it could be used to select anything including a button?

Yes : Demos — Q&A and tools for tiddlywiki

EDIT: actually to be more precise, it will work with any element that CAN be focused, so any form/interactive element . It wont work on span or div for example, unless you add the attribute tabindex="0" to them (but this is not a good practice).

The tabindex global attribute indicates that its element can be focused, and where it participates in sequential keyboard navigation (usually with the Tab key, hence the name).
tabindex - HTML: HyperText Markup Language | MDN

2 Likes