Jesse and I briefly discussed this on the channel last week. I asked about the possibility of having different behavior on an action based upon which button was pressed. For example, having a Preview and Submit form on a comment. I have gotten this to work like this:
<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if (get &#39;preview&#39;) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp; div {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { class is &#39;preview comment&#39; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # More code to render a preview here...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; };</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">};</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">div {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; { class is &#39;edit comment&#39; }
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; render_action $action;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; div {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { class is &#39;submit-buttons&#39; }
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form_submit</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label =&gt; _(&#39;Preview&#39;),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name =&gt; &#39;op&#39;,
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class =&gt; &#39;first&#39;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onclick =&gt; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refresh_self =&gt; 1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; submit =&gt; $action,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args =&gt; { preview =&gt; 1 },
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (get &#39;preview&#39;) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $action-&gt;button(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label =&gt; _(&#39;Submit&#39;),
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; submit =&gt; $action,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters =&gt; { </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;J:A:F-submit-&#39;.$action-&gt;moniker =&gt; 1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; };</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">};</span><br><br>The way this trick works is as follows: (1) I use a region argument named &quot;preview&quot; to tell the region to expect a preview, (2) the action will fail unless the &quot;submit&quot; parameter is set to a true value, (3) I use the &quot;parameters&quot; field on the submit button to set the submit value of the form. The trick is messy because it exposes some of Jifty&#39;s guts to submit the parameter and when you finish and press Submit it goes a little wonky because the region on the next page doesn&#39;t get reset quite correctly.
<br><br>First, if someone knows of a good way to do this in Jifty, I&#39;d love to know about it as I haven&#39;t thought of a better way. <br><br>Second, I&#39;d like to propose adding to the API a way of submitting additional action parameters on the button. It should be pretty easy to add since Jifty already handles the &quot;parameters&quot; bit here without much of a problem. My proposal is to add a new accessor to Jifty::Web::Form::Clickable: &quot;submit_args&quot; that could be used like this:
<br><br><span style="font-family: courier new,monospace;">$action-&gt;button(</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; label =&gt; _(&#39;Submit&#39;),</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; submit =&gt; $action,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; submit_args =&gt; [ $action =&gt; { submit =&gt; 1 } ],</span><span style="font-family: courier new,monospace;"></span><br>)<span style="font-family: courier new,monospace;">
;<br><br></span>As you can see I&#39;ve now provided by Submit button without exposing Jifty&#39;s &quot;J:A:F&quot; parameter nomenclature. The &quot;submit_args&quot; would be an array ref where the even indexes are the names of the actions or monikers being submitted and the odd indexes are a hash of arguments to add. As a shortcut, it would be possible to drop &quot;submit&quot; in cases where &quot;submit_args&quot; is used:
<br><br><span style="font-family: courier new,monospace;">$action-&gt;button(</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; label =&gt; _(&#39;Submit&#39;),</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; submit_args =&gt; [ $action =&gt; { submit =&gt; 1 } ],</span><span style="font-family: courier new,monospace;"></span><br>
)<span style="font-family: courier new,monospace;">;</span><br><br>Similarly, the &quot;onclick&quot; and related handlers of Jifty::Web::Form::Element should be modified to match, so that I could then perform:<br><br><span style="font-family: courier new,monospace;">
$action-&gt;button(</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; label =&gt; _(&#39;Submit&#39;),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp; onclick =&gt; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; submit_args =&gt; [ $action =&gt; { submit =&gt; 1 } ],</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; },</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">);</span><br><br>This would then perform the same action as above but allow me to use a JavaScript handler to perform the submit with arguments rather than a regular form post.
<br><br>In addtion to allowing two buttons to have different behaviors on the same action, this would allow for hidden parameters without having to add a separate input to the form. I see a potential here for more advanced link-based action submissions as well.
<br><br>Comments?<br><br>Cheers,<br>Sterling<br>