Pre-Fill a Field?

Is there any way to (pre)set a Field’s value so that when I select the field from the Field Name drop-down, the value will automatically appear in the Field Value field?

I know it’s possible to do for newly-created Tiddlers, as I already have a template Tiddler in this wiki that I use for new entries, with this field present and already populated, but I’d really like to be able to add the field into existing Tiddlers that were created earlier, before I started using the field.

It would be a great time-saver for me to have the value automatically show up so that I don’t have to type it each time. It’s a file path Catalog/Avatars/, and while it doesn’t seem THAT long, I have about 600 Tiddlers that possibly will need to have the field added… Plus, the method (if one does exist) would come in quite handy in the future with other wikis.

You can do this in one go by using action widgets and a button.

I made a quick demo with six hundred mostly-empty tiddlers with the tag Foo, with a fraction that have the field my-new-field (with random short strings for values), and the remainder without that field.

If – after backing up your wiki! – you add a tiddler with this button:

<$button>Add `my-new-field`
  <$list filter="[tag[Foo]!has[my-new-field]]">
    <$action-setfield $field="my-new-field" $value="xyz" />
  </$list>
</$button>

on clicking it, you will find all the tiddlers tagged “Foo” that do not have my-new-field, and set that field to "xyz". It will leave alone the tiddlers that already have a value for the field.

I would suggest that once you’ve verified that it works, you immediately delete this tiddler. Ones that modify huge swaths of your wiki are dangerous to leave around.

Perhaps it can be tested on an empty.html first?

In many ways we could call this a batch of actions when they are contained in a list.

@Chan_Droid I think we could have a default value in field creation but I wonder how often it would be of value. A drop down to the select the values anytime may be more useful.

  • I will research this a little

However to add a field later it is quicker and easier for you add a one off batch method as scott suggested. This possibly will not happen too often?

In one solution I have experimented with it did make something to find fields used in tiddlers, allow them to be added to the template for future tiddlers and then apply them to call tiddlers that dont have that field with a default value.

  • but this is not needed in most circumstances

Thank You so much for this, @Scott_Sauyet - It looks quick, (relatively) painless, and in a perfect world would most likely solve the problem nicely :slight_smile:

Of course, me being me, I live in a most imperfect world… :stuck_out_tongue:

  • First Thought: The Tiddlers do not all share a common Tag.
    I’ve wracked my brain trying to figure out a way, but can only see disaster emanating from trying to use this solution.
  • Second Thought: It might be possible to use this method by substituting a common Field instead of a Tag, as all of the Tiddlers do share several common Fields, but…
  • Third Thought: Not all the Tiddlers should have this field present, as I have a [<currentTiddler>has[avatar]] in my template, which would add an empty circle and push a line of text if there were anything except the full image link defined in the field :grimacing:

@TW_Tones has suggested something below that might better fit my use case, with a drop-down that could contain the needed text. Perhaps I’ll wait to see his eventual solution.

In any event, I am copying your solution and squirrelling it away in a Tiddler, as it might be of use in the future!

Thank You again :slight_smile:

@TW_Tones, your suggestion of a drop-down with the needed text in it sounds intriguing…

But wait. Now that I think of it, I once downloaded a plugin that purported to do just this!

scrounges through folder looking at old plugins…

Aha! It was Field Value Selector by some upstart noob calling himself @twMat :stuck_out_tongue:

I could not get it to work at the time I downloaded it, but after adding it to the wiki just now, it seems to function, and do exactly what we’re talking about:

So, I guess this problem is solved! :slight_smile:

Thank You for your time and brain-cell usage, though.

EDIT:
It was in the old Google Groups

Here is Mat’s page with the plugin

EDIT II
Okay, so it doesn’t actually work…

The drop-down functions, the list appears, but when I click on any of the entries, they are not added to the field and the drop-down disappears :sob:

So I’m still stuck.

I hope it helps at some time.

Note that the [tag[Foo]!has[my-new-field]] was not meant to be replaced by a particular tag and fieldname. Instead, the idea was that if you could write a filter that captured the tiddlers you wanted to convert, you could do this automatically. I have no idea if such a filter would be easy or even possible.

But if there is not a consistent value you are going to set this field to, then this technique will not work, not without more significant changes.

Another possibility is to use a FieldEditorFilter to connect an edit field for that field name. We do this by adding to the cascade like this to choose the right editor:

title: $:/my/config/FieldEditorFilters/my-new-field
tags: $:/tags/FieldEditorFilter
list-before: $:/config/FieldEditorFilters/default

[match[my-new-field]then[$:/my/config/EditTemplateFields/Templates/my-new-field]]

Then use the edit-text widget for the actual UI:

title: $:/my/config/EditTemplateFields/Templates/my-new-field

<$edit-text tag="input" class="tc-edit-texteditor tc-edit-fieldeditor" focus="yes" tiddler=<<currentTiddler>> field=<<currentField>> default="Catalog/Avatars/"/>
list-before: "$:/config/FieldEditorFilters/default"

Although I use the list-before here, usually, I just open up a tag pill for `$:/tags/FieldEditorFilter and drag this entry above the default one.

prefillField.json (622 Bytes)

There is some sort of bug, which I’m hoping an expert can explain: If you don’t edit the default text, it doesn’t get saved to the wiki. If you do edit it, even restoring the original version, it works fine.

It’s not clear to me if this would help, but it might.

I don’t know if this helps but there’s a plugin by @Maurycy that behaves similarly, although, I guess you’ll have to define new drop-down triggers for your own use case.

From the plugin documentation, these are the default drop-down triggers:

On the subject of limiting damage by code with far reaching affects that might have unintended effects (bugs) or might be triggered accidentally…

I usually use the ‘limit’ filter operator in cases like this - first I set a limit of say 10 so that only ten tiddlers are affected by my new code - when I know the code works ok I increase the limit or remove it.

Also I think you offer good advice to remove powerful code if it’s no longer required to be on the safe side.

Finally in the review tiddlers plugin I developed (with much appreciated help!) recently I wrote code to remove the two tiddler fields that this plugin adds and uses, this field removal is intended to help tidy things up for anyone who installs the tiddler and then, later, wants to remove it cleanly. There I added two “Do you really want to do this?” type steps as follows…

( the code still shows the use of the filter operator limit but this would be removed or increased in value for actual use, I just haven’t gotten around to doing it yet). The code asks twice before taking action.


\define removeAllReviewData()

<$button
tooltip="Delete all review data - you will be asked to confirm"
class=<<tv-config-toolbar-class>> >

<$action-confirm $message="Do you really wish to remove all review fields from tiddlers?">
<$action-confirm $message="Are you sure?">
<$list filter="[has:field[last-reviewed3]limit[10]]">
<$action-deletefield $tiddler=<<currentTiddler>> $field=last-reviewed3/>
<$action-deletefield $tiddler=<<currentTiddler>> $field=interval3/>
</$list>
</$action-confirm>
</$action-confirm>

<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/plugins/jonnie45/ReviewTiddlers/images/red-delete}}
</$list>
</$button>

\end

1 Like

A different solution for this kind of problem is the Commander plugin by @Mohammad.

It’s a great tool for many kinds of back-filling, refactoring, and other batch-operations.

Thank You, @Scott_Sauyet, for this, but I’m afraid it goes way over my level of comprehension of TW mechanics…

Reading through the other suggestions offered below, I’ve pretty much just given up on this idea and resigned myself to slogging through the remaining 500 or so Tiddlers manually as I’ve been doing.

@Sparrow, Thank You for the suggestion and link :slight_smile:

I took a look at the plugin, but don’t think it would really help me out much…

Yes, @Springer, I already have the Tiddler Commander plugin by @Mohammad :slight_smile:

I thought it might provide help, but my ‘unique’ use case is just making it nearly impossible to do this as a batch operation…

If I add the field and the prefix Catalog/Avatars/ to ALL the Tiddlers, then there are going to be a LOT of them that I’ll have to go back in and remove it from, as they do not have a corresponding avatar picture associated with them. I have to do this on a per-tiddler basis.

I’ve created a $list tiddler to display all tiddlers sorted by the author field, and am going through it alphabetically, adding the avatar field and filling it in manually.

I’ve even tried a few automated macro softwares, but none of them will allow me to automate the process, as it takes too many click and scroll and paste operations.

If only I’d thought to add the avatar ‘feature’ earlier, before I’d made so many tiddlers… :thinking:

If you can write the actions to change one tiddler you can do it on many tiddlers inside a button on a shared earlier. I know it takes time to learn but once you do it becomes quite easy.

If you can share the wiki or data tiddlers with a clear statement of what you want changed some of us can do it quickly.

Will there be some easy way to distinguish the ones that need the field from the ones that don’t?

If there is, perhaps it could be automated. If not, then I’m afraid you’re stuck with the manual work. Best of luck!

@Scott_Sauyet: No, not really. This wiki is a database of sorts of custom content that I’ve downloaded over the years for The Sims franchise of games, and the change that I’ve recently made is the addition of an Avatar picture for the creator of each mod or piece of content. I’m going through and finding (where possible) the original forum or blog post and grabbing the avatar pic for that user. As many of these items date all the way back to 2014, their original listings (and even the creators themselves) have long since departed the scene, so there is no pic to grab. That’s why I really can’t do it as a batch process…

@TW_Tones As previously stated, I think there isn’t a way to automate this or accomplish it in a batch process – It’s going to have to be done tiddler by tiddler.

The only way I can see is if Mat’s plugin had worked, as it would help simplify the process by being able to use a drop-down and select method, instead of having to type the field value. Alas, according to the later messages in the GG, it apparently stopped functioning in about 2020, and Mat never updated it past that time.

On the bright side, I continue making the edits manually, and only have about 400 or so tiddlers to go *sigh*

Again, Thank You everyone for all your help and suggestions :slight_smile:

  • I am confident this is not true, I have over 10 years experience with TiddlyWiki so far and never hit an impossible to do item.
  • But sometimes just jumping in and doing it manually you can finish in a not unreasonable time.
  • The offer to build the batch repair is still open;

@TW_Tones: Heh heh, I know, I’ve seen some very amazing solutions in the GG and here, to problems posed by users.

And I truly appreciate all your help and your kind offer to build a batch repair, but how could that be done? There’s no way to know which tiddlers should have the field added until I edit each one and see whether or not I can find an avatar pic for the particular creator…

The more I think about it, the more useful a plugin like Mat’s really is – in fact, it would be a great addition to the core, IMO. There really should be a drop-down on the field-value field, just like there is on the field-name field!

You were corresponding with Mat when he developed that plugin and seemed to have something similar in mind at the time – could you maybe look at the code and see why it stopped functioning?

My message above discusses a way to change the editor for a given field name.

I did it with a text input that defaulted to your prefix, but you could use a drop-down instead. I’ve done that a number of times.

Customizing EditTemplate field rendering explains how to do this. It’s non-trivial, but it’s also not terribly difficult.

@Scott_Sauyet: I played around a bit with this on tiddlywiki.com, but, sadly, could not get anything to work.

My knowledge of the inner workings of TW are very basic, especially when it comes to filters, and this is just too far over my head, I’m afraid.