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

62 views
Skip to first unread message

David

unread,
May 23, 2022, 9:04:21 PM5/23/22
to TiddlyWiki

<$tiddler tiddler="Dictionary Tiddler">
<$list filter="[all[current]indexes[]contains<!!searchText>sort[]]" variable=item>
    <$checkbox index=<<item>> checked="1" unchecked="0"/>
    &nbsp;<<item>><br/>
</$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".

Eric Shulman

unread,
May 23, 2022, 9:34:47 PM5/23/22
to TiddlyWiki
On Monday, May 23, 2022 at 6:04:21 PM UTC-7 David wrote:
```
<$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.

David

unread,
May 24, 2022, 7:36:35 AM5/24/22
to TiddlyWiki
```
<$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.

Eric Shulman

unread,
May 24, 2022, 8:38:12 AM5/24/22
to TiddlyWiki
On Tuesday, May 24, 2022 at 4:36:35 AM UTC-7 David wrote:
```
<$list filter="[<currentTiddler>indexes[]search:title:literal[Vegas]sort[]]" variable=item>
```
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

David

unread,
May 24, 2022, 12:12:15 PM5/24/22
to TiddlyWiki
Thanks!

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

Eric Shulman

unread,
May 24, 2022, 12:27:54 PM5/24/22
to TiddlyWiki
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

David

unread,
May 24, 2022, 3:12:35 PM5/24/22
to TiddlyWiki
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!!
Reply all
Reply to author
Forward
0 new messages