[tw5] Filter display of Dictionary List items based on tiddler's field??

<$tiddler tiddler=“Dictionary Tiddler”>
<$list filter="[all[current]indexes[]contains<!!searchText>sort[]]" variable=item>
<$checkbox index=<> checked=“1” unchecked=“0”/>
 <>

</$list>

</$tiddler>

I have this code in a tiddler, and it, as you can see, references data in the “Dictionary Tiddler” and my hope is that a field in this tiddler called, “searchText” could operate as a search so that only those indexes show that have that text.

So if “Vegas” was in that searchText field, this index would be retrieved, for instance… “5 Vegas Cigars” or “Las Vegas Strip”.

1 Like
<$list filter="[all[current]indexes[]contains<!!searchText>sort[]]" variable=item>

contains<!!searchText>> is incorrect for two reasons:

  • The field reference !!searchText should enclosed with curly braces: {!!searchText}, not angle brackets. Remember: the delimiters around filter operands correspond to the type of operand: square brackets are for literal text, angle brackets are for variable names, curly braces are for tiddler field references.
  • The contains operator is used to search within items of a list field. To search the items in the current filter input, use the search:title operator. Note that, although the input items are actually indexes, for the purposes of the search operator, they are handled as a list of “titles”.
  • Also note that, while all[current] is valid usage here, you could use <currentTiddler> instead. There’s no semantic difference, but <currentTiddler> is slightly more efficient than all[current], since it doesn’t have to parse the “current” operand to retrieve the tiddler title.

Thus, your filter should be:

<$list filter="[<currentTiddler>indexes[]search:title:literal{!!searchText}sort[]]" variable=item>

enjoy,
-e

P.S. I recommend visiting https://talk.tiddlywiki.org/ for a more active group in which to ask questions.

2 Likes
<$list filter="[<currentTiddler>indexes[]search:title:literal[Vegas]sort[]]" variable=item>

Thanks for replying. I’ll note that other forum for future questions.

But it seems your code snippet is not working with the variable/field in there. It works fine when I put some static text there, though, as seen in my line above.

The problem is due to the surrounding <$tiddler tiddler="Dictionary Tiddler">... </$tiddler> widget.
Because of this, the reference to {!!searchText} is looking in “Dictionary Tiddler” for the field contents.

One way around this is to remove the $tiddler widget and hard-code the “Dictionary Tiddler” title, like this:

<$list filter="[[Dictionary Tiddler]indexes[]search:title:literal{!!searchText}sort[]]" variable=item>
<$checkbox tiddler="Dictionary Tiddler" index=<<item>> checked="1" unchecked="0"/>
&nbsp;<<item>><br/>
</$list>

This allows the {!!searchText} reference to point to a field in the tiddler containing the <$list> widget, rather than the “Dictionary Tiddler” itself.

However… if the intention is to eventually enable lookups using different Dictionary Tiddlers, then the following code may be more useful:

<$edit-text field="searchText"/>
<$select field="dictionary">
<option>Dictionary Tiddler</option>
<option>Another Dictionary</option>
<option>Some Other Dictionary</option>
<option>etc...</option>
</$select>
<br>
<$let searchText={{!!searchText}}>
<$tiddler tiddler={{!!dictionary}}>
<$list filter="[all[current]indexes[]search:title:literal<searchText>sort[]]" variable=item>
<$checkbox index=<<item>> checked="1" unchecked="0"/>
&nbsp;<<item>><br/>
</$list>

</$tiddler>

</$let>

Basically, this sets a variable to the value of the searchText field before using $tiddler to change the current tiddler,
and then uses the value of that variable in the filter syntax. It also lets you select a dictionary tiddler title from a
droplist input, and then uses that title in the $tiddler widget, so that the lookup points to another dictionary while
still using the searchText input from the current tiddler.

enjoy,
-e

1 Like

Thanks!

That is perfect!. I think I have several other pages that can enjoy this kind of feature, as well.

One final tweak to the code:
instead of:

<$checkbox index=<<item>> checked="1" unchecked="0"/>&nbsp;<<item>><br/>

I suggest putting the item text within the body of the $checkbox widget, like this:


<$checkbox index=<<item>> checked="1" unchecked="0"> <<item>> </$checkbox><br/>

This allows you to click on the item text to toggle the checkbox.

-e

I’ll think about that. Sometimes I may want to select and copy the text. I’ll have to think of which I want to do more.

Thanks!!