How to use buttons to add and subtract numerical value to fields by 1

Here I have created a template for adding field values to tiddler fields using edit text widget. Now I want to add two buttons to interact with these edit text widgets - one button to add numerical value 1 to the field value and another button to substract numerical value 1 from that field value. Is it possible?

Sure:

<$let field="myfield" step="1">
<$button actions="""<$action-listops $field=<<field>> $subfilter="+[add<step>]:else[<step>]"/>""">+<<step>></$button>
<$edit-text field=<<field>> type="number" default="0"/>
<$button actions="""<$action-listops $field=<<field>> $subfilter="+[subtract<step>]:else[<step>negate[]]"/>""">-<<step>></$button>
</$let>

or with a macro:

\define btn-count(count) <$button actions="""<$action-listops $field=<<field>> $subfilter="+[add<__count__>]:else[<__count__>multiply[1]]"/>"""><<__count__>></$button>

<$let field="myfield">
<<btn-count "-1">>
<$edit-text field=<<field>> type="number" default="0"/>
<<btn-count "+1">>
</$let>
2 Likes

And for the ‘complete set’, lets be able to zero it.

<$button actions="""<$action-setfield $field="myfield" $value="0"/>""">0</$button>

Or delete it

<$button actions="""<$action-deletefield $field="myfield"/>""">{{$:/core/images/delete-button}}</$button>

Each button could be wrapped in a list with a conditional filter eg
<$list filter="[all[current]has[myfield]]" variable=~><$button actions="""<$action-deletefield $field="myfield"/>""">{{$:/core/images/delete-button}}</$button></$list>

1 Like

Thank you @telumire . I got time to test the solution using macro only. It works as intended. Although I might have to do some CSS to align every thing correctly.

I will test @telumire first solution and @TW_Tones solution today night