[TW5] How to default SelectWidget to the first entry in a list?

178 views
Skip to first unread message

Jeff Vance

unread,
Feb 26, 2017, 3:31:35 PM2/26/17
to TiddlyWiki
I have a tiddler with a SelectWidget that runs a filter to get a list of options.  I want the selection to always default to the very first entry, which will change over time as new tiddlers are created.  I haven't seen any examples of how to do this.  I see that I can set a default selection by name, but in my case the name I want will always change.  Is there a way to do this that I'm missing? I would love to just say, whichever is the first entry in the list, select that by default.  

David Szego

unread,
Feb 26, 2017, 10:54:38 PM2/26/17
to TiddlyWiki
What if the select's default= field called a macro, which basically ran the same list filter as the select, but only returned the first result? Theoretically that should do it...

David Szego

unread,
Feb 26, 2017, 10:55:54 PM2/26/17
to TiddlyWiki
Just an added thought, I'd make that macro a \define at the top of the tiddler with the select, to have it all together.

Mat

unread,
Feb 27, 2017, 1:29:55 AM2/27/17
to tiddl...@googlegroups.com
No complete answer, but I think this idea might work;

Use the same filter for a wrapping list from which you use only the first element as the default.

<outerlist...first[]>
<select ... default="{{!!title}}">
<innerlist>
<option>
</innerlist>
</select>
</outlerlist>

Never tested.

<:-)

Mat

unread,
Feb 27, 2017, 1:31:09 AM2/27/17
to tiddl...@googlegroups.com
ah, not that it's real code but it should say default={{!!title}} , i.e without quoteation marks.

Jeff Vance

unread,
Feb 27, 2017, 2:23:02 PM2/27/17
to TiddlyWiki

Hi guys:  thanks for the suggestions.  However, it seems to be not quite so simple.  Simply setting the default selection in the widget doesn't seem to actually activate that selection.  I assume I have to actually update the text of the state tiddler being used by the widget so it activates that selection.

Jeremy Ruston

unread,
Feb 27, 2017, 2:36:56 PM2/27/17
to tiddl...@googlegroups.com
Hi Jeff

Hi guys:  thanks for the suggestions.  However, it seems to be not quite so simple.  Simply setting the default selection in the widget doesn't seem to actually activate that selection.  I assume I have to actually update the text of the state tiddler being used by the widget so it activates that selection.

The description of the “default” attribute of the select widget is subtle:

> Default value to be used if the tiddler, field or index specifies a missing value

So, what the attribute does is provide the value to be displayed by the select widget if the tiddler/field/index is missing.

> I would love to just say, whichever is the first entry in the list, select that by default.  

Setting the select widget to a particular value is accomplished by assigning that value to the tiddler field/index that is bound to the widget. So, you’d need to explicitly assign the right value to that field/index in order to select the default that you want.

Best wishes

Jeremy





--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8d79de82-1bf5-4526-8d8a-0ebc2a0fa135%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave

unread,
Aug 27, 2017, 11:06:52 PM8/27/17
to TiddlyWiki
So in this example (see attached), how would you have the macro set that initial default value if there is no existing value already there?

Would there have to be a javascript if then statement within the <$select></$select> tags?
single.test.edit.2.png
single.test.view.3.png

Dave

unread,
Sep 8, 2017, 10:57:56 PM9/8/17
to TiddlyWiki

I figured it out -  If you do this:

\define s.test.result(mytestname,myresult:"neg")

if the value passed to it is empty, it sets the value to whatever you provide after the ":"


That solves my problem, but I don't know if its helpful for the OP (i.e. when the list is actually changing from one instance to another)


Reply all
Reply to author
Forward
0 new messages