Using a parameter in an action-generating procedure

The last few days, I think I’m having brain farts again. I can’t do things that seem they should be simple.

Can someone tell me why this doesn’t work:

\procedure my-action(name) 
<$action-setfield current=<<name>> />
\end 

''Current value'': {{!!current}}

<$button actions=<<my-action Foo>>>Foo</$button>
<$button actions=<<my-action Bar>>>Bar</$button>
<$button actions=<<my-action Baz>>>Baz</$button>

I think it should be obvious, but I’m trying to set a field value on the click of a button; that value is passed to the procedure creating my button actions.

But nothing happens.

And if I add logging actions,

\procedure my-action(name) 
<$action-log name={{{ [<name>] }}} static="strings work" />
<$action-log name=<<name>> but="parameters don't" />
<$action-setfield current=<<name>> />
\end 

I get

{ "name": "",  "static": "strings work" }

and

{"but": "parameters don't"}

Either that parameter is simply not being supplied, it gets lost in the shuffle, or I’m referring to it incorrectly. But I can’t figure out which it is.

Any suggestions?

Button test.json (527 Bytes)

Enclose the actions within quotes, like this:

<$button actions="<<my-action Foo>>">Foo</$button>
<$button actions="<<my-action Bar>>">Bar</$button>
<$button actions="<<my-action Baz>>">Baz</$button>

Without the surrounding quotes, the <<my-action ...>> macros are evaluated and expanded when the $button widgets are RENDERED. The quotes allow the enclosed macro calls to be retained as-is so they can be performed by invoking a separate parser when a $button is CLICKED. This “deferred processing” is particularly important if the actions depend upon values that have been input via user interactions with form elements.

-e

3 Likes

As always, thank you for the help, and the easy-to-understand explanation!