[TW5] Tag dependant fields

270 views
Skip to first unread message

Bob Flandard

unread,
Sep 28, 2015, 4:24:03 AM9/28/15
to TiddlyWiki
Hello,

Is this possible?

When a tiddler is tagged with "some tag" and opened in edit mode, there will automatically be defined some fields with default values and each field value has a drop-down list of allowed values which can be chosen from.

Thanks, Bob

Evolena

unread,
Sep 28, 2015, 4:43:10 AM9/28/15
to tiddl...@googlegroups.com
You can define a custom editTemplate element triggered by the tag.

Create a new (system) tiddler tagged with "$:/tags/EditTemplate". You can give it a field "list-after" set to "$:/core/ui/EditTemplate/body" (the fields you want with dropdown will be located after the body editing window, before the dropdown for the type field).
This tiddler will contain something like that (see the SelectWidget documentation for the options of the dropdown):

<$list filter="[all[current]tag[some tag]]">

Field name 1:
<$select field="field_name_1">
<option value=''></option>
<option>
value 1</option>
<option>value 2</option>
<option>
value 3</option>

</$select>


Field name 2:
<$select field="field_name_2">
<option value=''></option>
<$list filter='[...(filter that selects the values)...]'>

<option
><$view field='title'/></option>
</$list>
</$select>


</$list>

The fields will still be available in the classic way in edit view. To remove them, create for each field a system tiddler called "$:/config/EditTemplateFields/Visibility/field name" with the text "hide".

However, this will NOT automatically give a default value to the fields. The only way would be to create the tiddlers from a template.

Tobias Beer

unread,
Sep 28, 2015, 4:51:43 AM9/28/15
to tiddl...@googlegroups.com
Hi Evolena,

That was a worthy exercise, and you were quicker to reply. :-)
Sprinkles some line-break-dust for readability.

Best wishes,

— tb

Evolena

unread,
Sep 28, 2015, 5:00:39 AM9/28/15
to TiddlyWiki
Le lundi 28 septembre 2015 10:51:43 UTC+2, Tobias Beer a écrit :
Hi Evolena,

That was a worthy exercise,
and you were quicker to reply. :-)

It was something I only had to copy-paste (and adapt) from one of my own TW, hence the quick reply!

The only difference being,
I'd use more line-breaks
to make it more easily readable.

You're right, I've corrected it (not verified, hope there is no side effect). I don't remember why I haven't done it in my TW.

Bob Flandard

unread,
Sep 28, 2015, 5:56:35 AM9/28/15
to TiddlyWiki
Hello Evolena,

Thank you very much for your excellent and clever solution. The code above works as expected.

It seems that the select widget doesn't create a field for the first <option> even if it's explicitly chosen from the list, you have to pick one of the other <option> values first and then go back and select it. But I can live with that.

Thanks again, Bob

Tobias Beer

unread,
Sep 28, 2015, 6:25:19 AM9/28/15
to TiddlyWiki
Hi Evolena,

Could you please correct the above code
so as to use valid field names?

By the way, what you call "default" options
really are no default options,
so I would not call them that.

Best wishes,

— tb

Tobias Beer

unread,
Sep 28, 2015, 6:28:12 AM9/28/15
to TiddlyWiki
Hi Bob,

It seems that the select widget doesn't create a field for the first <option> even if it's explicitly chosen from the list, you have to pick one of the other <option> values first and then go back and select it. But I can live with that.

I don't quite understand what you mean with "go back".

A field is only being created or modified after a value has been selected.

In order to set a field's value, you need to actively select an option from the list, even if your browser happens to already show it as selected.

Best wishes,

— tb

Evolena

unread,
Sep 28, 2015, 6:49:58 AM9/28/15
to tiddl...@googlegroups.com


Le lundi 28 septembre 2015 12:25:19 UTC+2, Tobias Beer a écrit :
Hi Evolena,

Could you please correct the above code
so as to use valid field names?
Ah yes, I've not paid attention to my placeholder names. Obviously, the filter doesn't work as I've writen it.
 
By the way, what you call "default" options
really are no default options,
so I would not call them that.
I've reverted to what I originally used : an empty value. Less confusing indeed.

When the field affected by the select widget doesn't exist, the imput area displays the first option value, but it is not the real value, and thus it is not directly selectable in the dropdown... it's quite annoying, maybe the empty default value (see my edited code) is less confusing.

Tobias Beer

unread,
Sep 28, 2015, 7:08:42 AM9/28/15
to tiddl...@googlegroups.com
Hi Evolena,
 
I've reverted to what I originally used : an empty value. Less confusing indeed.

Yes, that's much better.

I think the SelectWidget should actually remove the field
when an option with an undefined value is selected,
with that being the initial state anyway.

— tb

Bob Flandard

unread,
Sep 28, 2015, 7:12:45 AM9/28/15
to TiddlyWiki
Hello tb,

By "go back" I mean that if the first item in the <option> list was the value required for the field, and you select it from the drop-down list, no new field is created. You have to assign one of the other <option> values first (this then creates the field and its value) and then select the first item from drop-down list (go-back to the list and select it).

Thanks to both, Bob


Tobias Beer

unread,
Sep 28, 2015, 7:38:41 AM9/28/15
to TiddlyWiki
Hi Bob,
 
By "go back" I mean that if the first item in the <option> list was the value required for the field, and you select it from the drop-down list, no new field is created. You have to assign one of the other <option> values first (this then creates the field and its value) and then select the first item from drop-down list (go-back to the list and select it).

In what browser / os would you be experiencing this?
I just tested on chrome / mac so far
and here there's nothing selected by default.
When I click on the select, it shows all the options
and displays a checkmark at the first option,
which ain't true, so you have to chose it.

Same on firefox / mac,
however not showing that checkmark.

— tb

Bob Flandard

unread,
Sep 28, 2015, 12:05:42 PM9/28/15
to TiddlyWiki
Hello tb,

I'm using Firefox with Windows 7. I don't see the check mark either. I think I'll just leave the first <option> as an empty string as suggested above.

All the best, Bob
Reply all
Reply to author
Forward
0 new messages