Hi, I'm attempting to abstract the following out into a widget:
<<set $PC_AGE = 18>>
<span id="pc-age-stat"><<print $PC_AGE>></span>
<<click "[+]">>
<<if $PC_AGE != $PC_MAX_AGE>>
<<set $PC_AGE++>>
<<replace "#pc-age-stat">>
<<print $PC_AGE>>
<</replace>>
<</if>>
<</click>>
<<click "[-]">>
<<if $PC_AGE != $PC_MIN_AGE>>
<<set $PC_AGE-->>
<<replace "#pc-age-stat">>
<<print $PC_AGE>>
<</replace>>
<</if>>
<</click>>
Here is what I've managed to come up with:
<<widget numberselect>>
<span id=$args[1]><<print $args[0]>></span>\
<<click "[+]">>\
<<if $args[0] != $args[2]>>\
<<set $args[0]++>>\
<<replace "$args[1]">>\
<<print $args[0]>>\
<</replace>>\
<</if>>\
<</click>>\
<<click "[-]">>\
<<if $args[0] != $args[3]>>\
<<set $args[0]-->>\
<<replace "$args[1]">>\
<<print $args[0]>>\
<</replace>>\
<</if>>\
<</click>>\
<</widget>>
If you try and run this, you'll get the correct output: 25 [+] [-], with the plus and minus clickable. However, clicking on the plus and minus throws and error:
Error: Uncaught Error: cannot execute macro <<replace>>: Syntax error, unrecognzed expression $args[1].
I've tried a few things:
<<replace "#$args[1]">>, <<replace "#" + $args[1]>>, etc -- I've even changed it so that the input would be the "#id". However, none of these have worked. Is there a way to make this work?
Comments
You also didn't include an example of the usage of the numberselect macro, base on your widget code I am going to assume it is something like the following:
Converting your first example into a widget is a little more complex than you thought, because you want to insert the id of an element, the name of a variable and the min/max values into the click handlers.
The following is one way to do what you asked, it uses <<print>> macros to create the click macro handlers: