An issue with select, field and list-links

In this wiki, set for the example, I’m facing an odd behaviour.

I’ve set a macro fieldSelect on the example of TW_Tones on one of his useful answers here.
The macro works well.
In a tiddler I invoke this macro to list tiddlers by a value of the city field. With the tiddler in the river everything works quite well.
But I tagged this tiddler with $:/tags/SideBar and in the sidebar, the list doesn’t work ?

I’m quite confused!

Sorry the linked wiki wasn’t saved. Now it is OK.

In your fieldSelect() macro, you have a $select widget, specified like this:

<$select field=selection>...</$select>

Note that the field parameter of the $select widget (i.e., the location where the chosen value is to be stored) is named selection. However, because no specific target tiddler parameter is provided, the chosen value will be stored in the current tiddler by default.

This works fine in the StoryRiver, because each tiddler displayed there automatically sets the value of <<currentTiddler>> to match that tiddler’s title.

However… unlike tiddler content rendered in the StoryRiver, tiddler content rendered in the Sidebar has no <<currentTiddler>> value! Thus, when you choose an item from the $select widget rendered in the Sidebar, the chosen item value is not stored anywhere.

One possible workaround approach is to add the following line at the beginning of the code in your fieldSelect() definition:

<$list filter="[<currentTiddler>!match[]else[SidebarSelection]]">

If there is a <currentTiddler> value (i.e., the value is not blank because the macro is rendered in the StoryRiver) then this line just acts as a pass-thru and leaves the value of <currentTiddler> as-is. However, if the value of <currentTiddler> is blank – because the macro is rendered in the Sidebar – then this line will set the currentTiddler variable to a fallback value of “SidebarSelection”, so that the remainder of the macro code has a valid target tiddler in which to save the selected value.

I hope this explanation helps you sort out what you want to accomplish…

Let me know how it goes.

-e

2 Likes

Thank you Eric for your answers well documented as always, but your proposed solution doesn’t seem to work.

My goal, is to use only this selection tiddler in the SideBar menu, not in the StoryRiver.
How can I achieve that then? Do I need to use a special tiddler to store the selection value?

How about this?

\define fieldSelect(myfield)
<$select tiddler=<<currentTab>> field=selection>
<$list filter='[all[shadows+tiddlers]each[$myfield$]get[$myfield$]]+[sort[]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
<option value="" >(aucun)</option>
</$select>
\end

example


city: <<fieldSelect 'city'>>

If you are using it in the Sidebar tab, the <<currentTab>> variable writes to the currently-shown tab’s fields.

Excellent ! Thank you Brian ! Because of you, today I learned something useful.
And what is nice is that work either in the tiddler in the StoryRiver and the SideBar menu.