Advice re dropdown lists

I am thinking about how I might do a dropdown list for data entry as follows:

I have many tiddlers of gun types, typeA typeB typeC etc

I have a gun tiddler than contains a field for its type and its value should be one of the gun type tiddler titles.

So I have a simple select statement using a filter to add the known gun types to the option list.

So far so good.

However, when the gun tiddler field is populated, I want the gun type field to be a wiki link to the stated gun type tiddler, it can contain more descriptive information on the gun type. So, I suspect the field value should be something like [[typeA]] so that when it displays, it shows up as a blue wikitext link that the user can click to navigate to the gun type tiddler.

But, on editing the gun tiddler, the edit form should remove the [[ and ]] so it just shows the gun type title again.

For the life of me, I can’t figure out how this might be accomplished.

Can someone point me in the right direction.

bobj

Unless the field is intended to hold a list of values, it is generally a bad idea to store the doubled square brackets syntax in the field value. Instead, you should use a $link widget or a filtered transclusion to render a link when it is displayed, like this:

<$link to={{!!fieldname}}/>
or
{{{ [<sometiddler>get[fieldname]] }}}

-e

1 Like

If it’s not much trouble, could you please elaborate on this or give some pointers as to why this is? I’m using double square brackets liberally in my fields, even in cases where the chance of needing a list of values is slim to none. I thought it was a fail-safe in case of having spaces in the values, in addition to having a list of values (prob. the same thing though).

Your own use-case illustrates why storing the square brackets is a bad idea.

Normally, when you edit a field value using an $edit-text widget the interaction is “live” so that as you type, the underlying stored field value is immediately updated and any other references to that field value are refreshed with each keystroke.

However, you have said you would like the $edit-text widget to somehow automatically "remove the [[ and ]]" and then add them back again when saving the input. While it is possible to do this, it adds a lot of complexity to the form interaction.

Basically, you would need to have the $edit-text widget operate on a temporary value that is stored separately from the “real” stored field value, and then only update the stored field value by using an $action-setfield widget in response to some explicit user action such as pressing a $button widget or using an $eventcatcher widget to respond to a $focusout event.

There are some rare instances where this is a useful technique, and I’ve done this myself for specific cases where making “live” changes to stored values causes unwanted refreshing to occur while typing.

But the wikitext coding for this is generally complicated and involves using an $eventcatcher widget to process $focusin and $focusout events that remove and restore the doubled square brackets, combined with a $:/temp/... tiddler to hold the intermediate field value.

It’s MUCH easier to simply avoid the entire problem by not storing the doubled square brackets, and using a $link widget or filtered transclusion syntax to display a link only when you need to.

-e

3 Likes

Forgot to mention earlier my top reason for using double square brackets when entering field values by hand: it lets me use the absolutely indispensable Auto Complete plugin.

For example, when creating a new book tiddler, instead of having to type in the author field, the name of the already existing tiddler:

William Gibson<enter>

I can simply type:

[[gib<enter>

and be done with it.

I remember seeing a “hack” at some point where entering a field value triggered a drop down suggestion list based on the already selected field name. I cannot recall where it was from, does it ring any bells with anyone else? It was so clever, simple and useful.

As others have discussed/alluded to, can we please have a (hopefully baked in) parametric, searchable, dropdown macro/function/procedure?