Tiddlywiki5: Why no tm-set-field message?

Created on 1 Dec 2020  路  8Comments  路  Source: Jermolene/TiddlyWiki5

Reading through the list of available messages, I'm puzzled that there's a tm-add-field message to add a field with empty contents, but no tm-set-field message (which would set the value of the field and also create it if it didn't yet exist). You can set the contents of a field with a button widget or an ActionSetFieldWidget, so why is there no tm-set-field message counterpart to those widgets?

All 8 comments

Hi @rmunn the tm-add-field, along with the associated <$fieldcatcher> widget is an ancient kludge from the very, very early days of TW5. It is on my list for things that should be deprecated when we get to v5.2.x on the understanding that everything could be done with the <$action-setfield> widget. But perhaps there are usecases still?

Probably not; I was just browsing through the list of messages trying to understand some of TW's internals that I don't fully have my head around, and whether they could be beneficial to my project. Given that the action widgets do everything that the field mangler widget does but do it better, I'm :+1: on deprecating it.

Now that it's come up, perhaps we should start flagging features as deprecated more clearly. I think @pmario made some contributions on this.

The way to flag things as deprecated is to add the $:/deprecated tag and place the <<.deprecated-since "version" "See here instead">> macro in the tiddler text, right? If so, see #5174 for a (minor) spelling fix to the deprecation warning.

I was initially relieved to read that tm-add-field is an "ancient kludge" that can be forgotten about, since I was definitely bewildered by it.

But after inspecting $:/core/ui/EditTemplate/fields it turns out that tm-add-field can set field values as well it seems,
through the use of optional named parameters (i.e. $name and $value or field=value). This isn't documented currently it seems.

Also, what about the tm-add-tag and tm-remove-tag messages? Unless I'm missing something, it seems like that's the easiest. way to add or remove tags. So I guess I would prefer those two messages not be deprecated (in fact I'd love if they were upgraded to allow choosing which "tag" field is used...)

The easiest way to add or remove tags would be to use the ActionListopsWidget, as follows:

<$button>
<$action-listops $field="tags" $subfilter="newtag"/>
Add tag "newtag"
</$button>

<$button>
<$action-listops $field="tags" $subfilter="-newtag"/>
Remove tag "newtag"
</$button>

Of course, you don't have to use a button; you can trigger an action widget with several different widgets. (With more ways to trigger actions coming in 5.1.23). And if you want to use a checkbox to set or remove a tag, that's even easier:

<$checkbox tag="done"> Done</$checkbox>

That's from the TaskManagementExample and creates a checkbox which is linked to the "done" tag, e.g. if the tiddler has that tag then the checkbox is checked, unchecking it removes the tag, checking it adds the tag, and so on.

There are other ways to do it, too, but those are the two simplest.

Thank you very much for the info about the Action Listops widget!
I vaguely knew it was possible using listops "or something" but thought it would require trickery with filters.
I feel like a lot of users may be intimidated by filters/listops and thus not know these tricks (or maybe that's just me).

I still feel that the undocumented behavior of tm-add-field should be documented for posterity and/or people looking at old plugins/wikis... But anyway

I still feel that the undocumented behavior of tm-add-field should be documented for posterity and/or people looking at old plugins/wikis... But anyway

Likewise, I'd be happy to see a PR for that docs update.

Another thought is that <$action-listops $field="tags" $subfilter="-newtag"/> is undeniably complex. We could ameliorate that problem by providing a bunch of core action macros with friendlier functionality. In this case, <<action-removetag tags newtag>>. We could aim to capture say half a dozen of the most common idioms of the <$action-listops> widget.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

morosanuae picture morosanuae  路  6Comments

twMat picture twMat  路  4Comments

KendrickLamarck picture KendrickLamarck  路  4Comments

twMat picture twMat  路  5Comments

saqimtiaz picture saqimtiaz  路  5Comments