Newbie questions: How can list elements from a data-tiddler be excluded?

Hi,

I have a couple of questions I’ve been having trouble with:

  1. If I have a list of things like “1 2 3”, what’s the right filter syntax to exclude 3 from that?
  2. If I have a data tiddler named DataTiddler that has two columns (see below), is this a recommended way to create a select from it:

The data tiddler:

1: ok
2: great
3: N/A

The select:

<select>
<$list filter="[[DataTiddler]indexes[]nsort[]]" variable="index">
<option value=<<index>>><$view index=<<index>> tiddler="DataTiddler"/></option>
</$list>
</select>

What if I wanted to exclude a certain value from the options?

In the filter you can remove a specific title as follows

"[[DataTiddler]indexes[]nsort[]] -[[3]]"

But I expect you could detail. What you want to achive with this a little more

The [[ ]] is optional.

1 Like
  • You need to use the TWCore <$select> widget, not the HTML <select> element. Otherwise, your selection will not be stored anywhere.
  • You must also specify a target tiddler (or at least a target fieldname); e.g. <$select tiddler="MySelection"> or <$select field="myselection">. Otherwise, the widget will default to setting the text field of the current tiddler, which would immediately overwrite your code as soon as you make a selection!
  • You may also want to specify a default value to use when the target tiddler or field doesn’t exist.

Thus, something like this:

<$select tiddler="MySelection" default="3">
<$list filter="[[DataTiddler]indexes[]nsort[]]" variable="index">
<option value=<<index>>><$view index=<<index>> tiddler="DataTiddler"/></option>
</$list>
</$select>

To exclude a certain value you can write:

<$list filter="[[DataTiddler]indexes[]nsort[]!match[3]]" variable="index">

If you want to exclude based on the displayed text of a certain value, you can use the :filter[...] filter run prefix, like this:

<$list filter="[[DataTiddler]indexes[]nsort[]] :filter[[DataTiddler]getindex<currentTiddler>!match[N/A]]" variable="index">

Alternatively, you could use a nested $list widget, like this:

<$list filter="[[DataTiddler]indexes[]nsort[]]" variable="index">
   <$list filter="[[DataTiddler]getindex<index>!match[N/A]]">
      <option value=<<index>>><$view index=<<index>> tiddler="DataTiddler"/></option>
   </$list>
</$list>

enjoy,
-e

2 Likes

This was just a theoretical question, I ran into this while experimenting with filters. Of no immediate practical consequence, but thank you so much for that tip!

1 Like

Thank you @EricShulman , I need to play with all this. Trying to grok TW concepts and this definitely helps. This is a great start for me – spent a bunch of time googling last night and couldn’t find a definitive pattern. Thank you so much.

1 Like

3 posts were split to a new topic: How can I sort Tabs-Order