How to set a field value in another tiddler in a select (Solved)

Hi,

I have some trouble finding the right way to set a field value based on the select chosen.

<$select tiddler='$:/wim/CampaignNow'>
actions='<$action-setfield $field="StartingIP" $tiddler="NewCharacter" $value={{{  [{!!IP Cost}]  }}} />'
<$list filter='[tag[Campaign]]'>
<option><$view field='title'/></option>
</$list>
</$select>
<$tiddler tiddler={{$:/wim/CampaignNow}}>
 &nbsp;&nbsp;&nbsp;{{!!IP Cost}}
</$tiddler> 

note: the {{{ [{!!IP Cost}] }}} part is where i’m stuck.

after the select is a way to display the value.

That value needs to go to to {{NewCharacter!!StartingIP}}

The problem is that it comes from one of 5 other tiddlers, which is chosen by the $select.

Below the select is how I can find it outside of the select, the problem is finding that within the select, as the currentTiddler will probably not work in the actions action-setfield…

Maybe I am using too much indirection?

This does work:


<$button actions=<<set-campaign 0>>>
Vagabond
</$button>&nbsp;<$button actions=<<set-campaign 27>>>
Adventurer
</$button>&nbsp;<$button actions=<<set-campaign 54>>>
Heroic
</$button>&nbsp;<$button actions=<<set-campaign 81>>>
Epic
</$button>&nbsp;<$button actions=<<set-campaign 108>>>
Legendary
</$button>&nbsp;{{NewCharacter!!StartingIP}}

with

\define set-campaign(val)
<$action-setfield $tiddler="NewCharacter" $field="StartingIP"  $value="$val$" />
\end

But it requires 5 buttons. Other selections may involve 18 or 55 or 100+ choices, so that is not really workable.

on https://aesirius-rpg.tiddlyhost.com/ the wiki can be found, with the tiddler in question Campaign Selection

Try this:

<$action-setfield $tiddler="NewCharacter" StartingIP={{{ [{$:/wim/CampaignNow}get[IP Cost]] }}}/>

Notes:

  • When the $select actions are triggered, the selected value is in the text field of $:/wim/CampaignNow
  • The “filtered transclusion” gets that selected value (which is the title of a tiddler) and then uses get[IP Cost] to fetch the cost value from that tiddler
  • Note also I’ve used the shorter field=value syntax in the $action-setfield. In general, the only time you will need to use the separate $field=... and $value=... syntax is if the field name is contained in a variable or is otherwise computed on-the-fly.
  • This same shorter syntax can be used in set-campaign(val), like this:
<$action-setfield $tiddler="NewCharacter" StartingIP="$val$"/>

enjoy,
-e

1 Like

Thanks for the answer so far.

It seems like it doesn’t work yet.

<$select tiddler='$:/wim/CampaignNow'>
actions='<$action-setfield $tiddler="NewCharacter" StartingIP={{{ [{$:/wim/CampaignNow}get[IP Cost]] }}}/>'
<$list filter='[tag[Campaign]]'>
<option><$view field='title'/></option>
</$list>
</$select>
<$tiddler tiddler={{$:/wim/CampaignNow}}>
 &nbsp;&nbsp;&nbsp;{{!!IP Cost}}
</$tiddler> 

Is the new version of the code, it displays the IP cost correctly after the the select, but it doesn’t change the field value.

StartingIP is used in the NewCharacter tiddler and IP Cost comes from one of the Campaigns, for example {{Heroic Campaign!!IP Cost}}

The buttons keep working with the simplified syntax, but the selection doesn’t.

actions go inside the chevrons of the select, try

<$select tiddler='$:/wim/CampaignNow'
actions='<$action-setfield $tiddler="NewCharacter" StartingIP={{{ [{$:/wim/CampaignNow}get[IP Cost]] }}}/>'>
1 Like

Unless you need to have that value set simultaneously in multiple places, might I suggest that you can avoid the $action-setfield and simplify:

<$select tiddler="NewCharacter" field="StartingIP">

<$list filter=[tag[Campaign]]>

<option value={{!!IP Cost}}> {{!!title}} </option>

</$list>

</$select>

{{NewCharacter!!StartingIP}}

/Mike

1 Like

thanks, this solved it.

the mwiktowy solution did not work as there was no name on the selection field. When pressed there were no options.

But thanks to all three you saved me 100’s of buttons =)