standard search field into a tiddler

209 views
Skip to first unread message

tobaisch

unread,
Dec 10, 2017, 10:10:44 PM12/10/17
to TiddlyWiki
How do I get the standard search field into a tiddler?
thx
regards
Tob

TonyM

unread,
Dec 11, 2017, 12:28:45 AM12/11/17
to TiddlyWiki
$:/core/ui/SideBarLists seems to contain what you are after

If you clone this tiddler and remove the first line
<div class="tc-sidebar-lists">

and the last 2 lines
<$macrocall $name="tabs" tabsList="[all[shadows+tiddlers]tag[$:/tags/SideBar]!has[draft.of]]" default={{$:/config/DefaultSidebarTab}} state="$:/state/tab/sidebar" />

</div>

Then you can use the resulting code, or more practically transclude your new tiddler in any tiddler

{{mySearchTiddler}}


Regards
Tony

tobaisch

unread,
Dec 11, 2017, 6:53:32 AM12/11/17
to TiddlyWiki
That works fine so far. Thank you very much
However, it bothers that the drop down pop-up of the search results over the text persists.
It should disappear after I've click a result.
Regards
Tob

Riz

unread,
Dec 12, 2017, 2:39:41 AM12/12/17
to TiddlyWiki


Search, like many other stuff in TW5, is essentially produced by list widget with appropriate filter parameter.

Add the following code to a tiddler.

<$edit-text tiddler="$:/temp/mysearch" tag="input" default="Search"/>

Essentially it creates a textbox where the typed content is stored in the tiddler "$:/temp/mysearch".  To understand the rest of the options, refer https://tiddlywiki.com/#EditTextWidget.

Now we got to create the results.  Add the following code wherever you the want the search results to appear (it can be in the same tiddler as the text box or anywhere else).

<$list filter="[search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
<$link><<currentTiddler>></$link><br>
</$list>


Now remember,  this is the least minimum code required to produce search results. As you can see,  the search results include both standard tiddlers and system tiddlers. Now we tweak according to our wishes.  We do not want system tiddlers in our results,  so we use filter like this

<$list filter="[!is[system]search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
<$link><<currentTiddler>></$link><br>
</$list>


Or, we want to search in system tiddlers only,  so we go like

<$list filter="[is[system]search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
<$link><<currentTiddler>></$link><br>
</$list>

You can customise it further by specifying which fields to search in, what kind of tiddlers to search in and so on. Refer: https://tiddlywiki.com/#Filter%20Operators.


Now, you can add buttons like "clear the searchbar". "open the advanced search" etc if you want. The snippet is as follows.

<$reveal state="$:/temp/mysearch" type="nomatch" text="">

<$button class="tc-btn-invisible" tooltip="Clear searchbar">
<$action-setfield $tiddler="$:/temp/mysearch" text=""/>
{{$:/core/images/close-button}}
</$button>

<$button class="tc-btn-invisible" tooltip="Advanced Search">
<$action-setfield $tiddler="$:/temp/advancedsearch" text={{$:/temp/mysearch}}/>
<$action-setfield $tiddler="$:/temp/mysearch" text=""/>
<$action-navigate $to="$:/AdvancedSearch"/>
{{$:/core/images/advanced-search-button}}
</$button>

</$reveal>


Another customisation I personally like is showing search results only after you finish typing and hit enter key. Here is the code for that:

\define enterthesearch()
<$action-setfield $tiddler="$:/temp/mysearch" text={{$:/temp/mysearch1}}/>
<$action-setfield $tiddler="$:/temp/mysearch1" text=""/>
\end


<$keyboard key="enter" actions="enterthesearch">
<$edit-text tiddler="$:/temp/mysearch1" tag="input" default="Search"/>
</$keyboard>


<$list filter="[!is[system]search{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
<$link><<currentTiddler>></$link><br>
</$list>



Now finally coming to your request of closing the tiddlers whenever you click on a link. As a matter of fact you can do any number of actions when you click on a link. Just add what you want to do in the macro definition as given below.

\define dowhateveryouwant()
<$action-navigate $to=<<navigateTo>>/>
<$action-sendmessage $message="tm-close-tiddler"/>
<$action-setfield $tiddler="$:/SiteTitle" $value=<<navigateTo>>/>
\end

<$edit-text tiddler="$:/temp/mysearch" tag="input" default="Search"/>

<$linkcatcher actions=<<dowhateveryouwant>>>
<$list filter="[!is[system]search{$:/temp/mysearch}minlength[5]] -[[$:/temp/mysearch]]">
<$link><<currentTiddler>></$link><br>
</$list>
</$linkcatcher>

TonyM

unread,
Dec 12, 2017, 3:33:06 AM12/12/17
to TiddlyWiki
Lovely work Riz

Damon Pritchett

unread,
Dec 14, 2019, 6:16:44 PM12/14/19
to TiddlyWiki
Hey Tony,

I'm trying to incorporate a custom search box using some of the code that Riz had above. It works for my needs except that if there is nothing typed in the search box, everything matching the filter shows up. I tried using minlength, but haven't been able to get it to work. The code I'm using is below:

<div class="tc-sidebar-lists tc-sidebar-search">


<$edit-text tiddler="$:/temp/mysearch" tag="input" default=""/>
<$reveal state="$:/temp/mysearch" type="nomatch" text="">
<$button class="tc-btn-invisible" tooltip="Clear searchbar">
<$action-setfield $tiddler="$:/temp/mysearch" text=""/>
{{$:/core/images/close-button}}
</$button>
</$reveal>


<$list filter="[tag[Railroads]search:title{$:/temp/mysearch}minlength{$:/config/Search/minlength}] -[[$:/temp/mysearch]]">
<$link><
<currentTiddler>></$link><br>
</$list>


</div>

Where am I going wrong? I'd like no results showing until I've typed at least three characters.

Thanks,

Damon

On Tuesday, December 12, 2017 at 1:33:06 AM UTC-7, TonyM wrote:
Lovely work Riz

Mark S.

unread,
Dec 14, 2019, 6:33:18 PM12/14/19
to TiddlyWiki

You need to move the minlength so it nests the query:

<$list filter="minlength{$:/config/Search/minlength}]" emptyMessage="Search is too short" >
<$list filter="[tag[Railroads]search:title{$:/temp/mysearch}] -[[$:/temp/mysearch]]">
<$link><
<currentTiddler>></$link><br>
</$list>
</$list>

Be sure $:/config/Search/minlength is set to whatever starting length value you need.

Damon Pritchett

unread,
Dec 14, 2019, 6:42:57 PM12/14/19
to TiddlyWiki
Hi Mark,

I checked the value of minlength and it is 3. I copied your code over, but it didn't make any difference. If there is nothing typed in the text box, all tiddlers tagged Railroads show up in the list. As I'm typing each character changes the list even the first character.

Damon

Eric Shulman

unread,
Dec 14, 2019, 6:53:02 PM12/14/19
to TiddlyWiki
On Saturday, December 14, 2019 at 3:33:18 PM UTC-8, Mark S. wrote:

<$list filter="minlength{$:/config/Search/minlength}]" emptyMessage="Search is too short" >

I think there's some missing filter syntax... the minlength[] filter needs some input... such as the actual text entered for the search.

something like this:

<$list filter="[{$:/temp/mysearch}minlength{$:/config/Search/minlength}]" emptyMessage="Search is too short" >

-e

TonyM

unread,
Dec 14, 2019, 7:44:05 PM12/14/19
to TiddlyWiki
tobaisch

Can you use another list field to wrap the search results and only display them if $:/temp/mysearch is non blank

<$list filter="[[$:/temp/mysearch]has[text]]" emptyMessage="No search string" variable=nul>
  Search and display results here
</$list>

Using the has[fieldname] 
is only true if text is non-blank rather than has:field[text] which is if it even exists and empty

Regards
Tony

Damon Pritchett

unread,
Dec 15, 2019, 3:00:28 PM12/15/19
to TiddlyWiki
Thanks to Mark, Eric and Tony. Once I incorporated all three of their suggestions, it worked just great!

Can't say this often enough: Tiddlywiki and this support group are awesome!

Damon
Reply all
Reply to author
Forward
0 new messages