How to create a single button to add different fields or field values to a tiddler in multiple sequential steps

I want to create a single button (view toolbar button) that can

  1. add different fields (for example, to add fields like abc, def) to a particular tiddler in multiple sequential steps
  2. add different field values to a particular field (for example to add field values one two or three to the field abc) of particular tiddler in multiple sequential steps.

Is it possible ?

You could create a button that, when clicked, copies the currentTiddler title to the text field of a temp tiddler and opens a modal dialog.

The dialog could have 2 text boxes: one for a field name and one for the value. The boxes would write to fields in the created temp tiddler (eg fieldName and fieldValue).

A confirmation button in the dialog could use the textbox values to add the field and field value to the currentTiddler, and also clear the text boxes so you could start the process over for another field.

A cancel button could just delete the temp tiddler, or clear the fields, depending your preference.

You could make a new Close button for the modal that closes the dialog and also delete the temp tid.

If you plan on adding the same few fields often, the first text box could instead be a drop-down menu of field names.

The same modal could also grab the currentTiddler field-value pairs and copy to the temp tid, with text boxes to allow for editing. The confirmation button would then also write these new values back to the currentTiddler.

1 Like

Would a Toolbar button that has a dropdown when clicked listing possible actions on a tiddler including create fieldname or set fieldname be what you are looking for?

  • I Have one under development

I also found value having an “add specific fieldname” button (behind the more button), but once added, a button appears (conditionally) on the toolbar to set its value, in particular stamp it with a now timestamp.

I think what you are asking for should be a readily available feature on tiddlywiki, because it is the one of the next steps in design requirements on top of core features.

2 Likes

@Brian_Radspinner I will try what you have told.
I will show what I am trying to implement. Take a look at this wiki. Here there is a viewtoolbar button which add a field called class to the tiddler with field value multicol2. What I want is on the second click of the same button, the field value to change to multicol3 and on the next click to multicol and on the last click to delete the field.

I have seen something similar in this muuri add on button by @fastfreddy

This could also be a possibility. Do you have a working example ?

Here is an “unpublished” package of what I have called a “more tiddler actions” button dropdown. It introduces a ViewToolbar button with a drop down that then transcludes the tiddlers with the tag $:/tags/more-ViewToolbar.

  • This is unpublished because it is intended to be cloneable to make more similar buttons and thus deserved a higher quality of testing and documentation if to be published. And to be honest its part of my personal rapid development tools.
  • buttons-more-tiddler-actions.json (11.5 KB)
  • What you would do with this is create another tiddler with the $:/tags/more-ViewToolbar tag, containing your conditional items to appear in the dropdown, similar to the below example.

I have also included a single tiddler with the above tag that displays different items in the dropdown menu according to various conditions, as an example start-end-date handling.json (4.4 KB)

  • It is my first proof of concept for the more general solution of adding and changing fields on tiddlers.
  • It handles addition, stamping and deletion of start-date and end-date fields
  • It uses the existence of an empty start-date field as one state, and one stamped with a date as another. ie when empty it needs to be started, stamped it has started at this date and time.

If you find it difficult to make use of (As it was intended to be cloned into a new dropdown as needed ) ask, and I will generate a custom button for you to use (rather than the above package) and you can be a gunnie pig with a request for feedback from me.

  • otherwise see what you can extract
2 Likes

You can give the following code a try. Probably a more elegant option is available, but this seems to work for the requested value cycling:

<$button>
<$action-setfield $tiddler=<<currentTiddler>> class={{{ [<currentTiddler>!has[class]then[multicol2]] ~[<currentTiddler>class[multicol2]then[multicol3]] ~[<currentTiddler>class[multicol3]then[multicol]] }}} />
<$list filter="[<currentTiddler>class[multicol]]" variable="deleteClass">
<$action-deletefield class />
</$list>
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/spiral}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text">
Display
</span>
</$list>
</$button>
3 Likes

Back to the OT, yes this is easy because you just have a set of list widgets with filters that sequentially become true

  • [all[current]!has[abc]] create abc button
  • [all[current]has[abc]] create def button
  • [all[current]has[def]] etc…

In my above reply this would work with the $:/tags/more-ViewToolbar and on the tiddler and I have also tested @Brian_Radspinner example.

1 Like

Thank you @Brian_Radspinner . That does the job. From where to learn to write code like this, particularly the action setfield widget. I know to use action set field widget in a basic way. But this was way above my skill.

I have one more doubt. How to modify this code if I want to add fields abc, def, ghi to the tiddler sequentially, after deleting the previous one and finally delete the field ghi. I don’t want to add any field values in this case.

@TW_Tones thank you for sharing. I havent got time to check it. I have just woke up after sleep. This will definitely have some use cases for me, because currently my viewtoolbar is cluttered with many custom buttons. I can bring many similar buttons under one by using the drop-down approach.

1 Like

Hi @Brian_Radspinner

Very nice solution. Thank you.
EDIT i: I added this an as example to Shiraz 3.0.0

Comment i

This is a very clever solution and worth to be added to official documentation, it does as below

  1. if there is no class field, create it and set its value to multicol2
  2. if tiddler has the class field with muticol2 value, then change the value to multicol3
  3. if tiddler has the class field with multicol3 value, then change the value to multicol
  4. if tiddler has the class field with multicol value, then delete the value (an empty field)

So, I believe there is no need to delete the class, and the below portion of code can be commented out (removed)

<$list filter="[<currentTiddler>class[multicol]]" variable="deleteClass">
<$action-deletefield class />
</$list>

Comment ii
A filter transclusion only returns the first result when it is used as widget attribute value, so the above code can be written as

<$action-setfield $tiddler=<<currentTiddler>> class={{{ [<currentTiddler>!has[class]then[multicol2]] [<currentTiddler>class[multicol2]then[multicol3]][<currentTiddler>class[multicol3]then[multicol]] }}} />

But I like your solution as it is much more semantic.

Comment iii
You may use the toggle operator and replace the action-setfield with action-listops

<$action-listops $tiddler=<<currentTiddler>> $field="class" $subfilter="+[toggle[multicol2],[multicol3],[multicol],[]]" />
3 Likes

Thank you very much Mohammad for the explanation and for adding my code to Shiraz, it’s an honor.

I really like your changes to the code. I’m always happy to be told of other/better ways to accomplish a goal, it gives me more options in the future. :+1:

1 Like