Select widget to edit multiple fields?

Hi! I hope it’s the right place to ask.

I wanted to have a select widget, where when choosing an option, multiple fields are edited (instead of just one). Is it possible? Maybe with some macro and the action widget? I can’t figure it out.

Example of what I mean:

<$select field1=field1name field2=field2name>
<option value1=content1a value2=content2a>option A</option>
<option value1=content1b value2=content2b>option B</option>
</$select>

I need it to organize some sheets for a personal project!

\define select-actions()
<$action-setfield field2name={{!!field1name}} />
\end

<$select field="field1name" actions=<<select-actions>> >
<option value="content1a">option A</option>
<option value="content1b">option B</option>
</$select>

Try something like the above. In the actions you will need to determine what value you want to be assigning to the second field, based on what was assigned to the first field. Using a filtered attribute to assign the field value in $action-setfield will probably be handy.

Should the filter be something like:

<$action-setfield field2name=[{!!field1name}match[content1A]then[content2A]else[content2B] />

However, I actually need it to set three different fields per option… And now I don’t know how to “nest” if-then-if-then-else!

1 Like

To choose between 3 different values to set in a single field:

\define selection-actions()
<$action-setfield	
	field2name={{{ 
				[{!!field1name}match[content1A]then[content2A]] 
				:else[{!!fieldname}match[B]then[C]]
				:else[{!!fieldname}match[D]then[E]]
			}}} 
/>
\end

To set 3 different fields:

\define select-actions
<$list filter="[{!!fieldname}match[A]]" variable="null">
	<$action-setfield tiddler="mytiddler" fieldA="value A" fieldB="value B" fieldC="value C"
</$list>
<$list filter="[{!!fieldname}match[B]]" variable="null">
	<$action-setfield tiddler="mytiddler" fieldA="value X" fieldB="value Y" fieldC="value Z"
</$list>
<$list filter="[{!!fieldname}match[C]]" variable="null">
	<$action-setfield tiddler="mytiddler" fieldA="value G" fieldB="value H" fieldC="value I"
</$list>
\end
1 Like

Very interesting! That means we can use several :else clauses within a filter. The first will win and remaining will be ignored.

This is similar to what you may do to use different actions based on the modifier key on click with a filter such as [<modified>match[ctrl]], [<modified>match[alt]].