[tw5] Upon first edit, field creates a temporary tiddler, causing the focus to move away from the field

I’ve got a search field that only takes effect after clicking an “Apply” button.

<$tiddler tiddler="$:/temp/BAM/Settings">
<$edit-text field="search_draft"/>
<$button class={{{ [{!!search_draft}!match{!!search}then[blinking]] }}} disabled={{{ [{!!search_draft}match{!!search}then[yes]else[no]] }}}>
<$action-setfield search={{!!search_draft}}/>
Apply
</$button>

Every time, the first time entering text in that search field, the focus would move away from the field right after typing the first character.

Never any focus issue after that first-time-first-keypress every time I used the TiddlyWiki instance.

The problem: the temporary tiddler, which doesn’t exist until something is typed in the field, gets created on the first keypress in that field. That causes the focus to move away from the field.

What I did: create that temporary tiddler on Startup of the TiddlyWiki instance.

Problem solved.

When the $:/temp/BAM/Settings tiddler is first created, it causes everything following the $tiddler widget to be refreshed, which triggers the loss-of-focus that you observed. While creating the temporary tiddler on startup certainly does fix this issue, there is another solution that doesn’t require a startup action. Just move the $tiddler widget AFTER the $edit-text widget and add a tiddler=... parameter to the $edit-text widget, like this:

<$edit-text tiddler="$:/temp/BAM/Settings" field="search_draft"/>
<$tiddler tiddler="$:/temp/BAM/Settings">

Thus, the $edit-text widget is no longer subjected to the spontaneous refresh when the temp tiddler is first created, but everything else still works as before.

Another way to achieve this same result is to replace the $tiddler widget with

<$list filter="$:/temp/BAM/Settings">

which has the side effect of setting the currentTiddler value to $:/temp/BAM/Settings, but doesn’t cause the loss-of-focus refresh to be triggered.

enjoy,
-e

Eric, that information is pure gold. Why that isn’t in the documentation could inspire some conspiracy theories.

Those alternative options you offer up, though: man, power to whoever’s boat that floats, but that does not semantically my crank turn.