Hi,
If you have only got 2 buttons then you can take advantage
of the fact
that disabling a button means that it won't get posted. In
the code
below, when the user presses 'Save', the save_button gets
disabled and
the controller sees the presence of preview_button. If
'Preview' gets
pressed then the first button ('save_button') gets seen as
described in
the earlier posts. It's ugly and the controller logic looks
upside down,
but it seems to work for me...
<%= submit_tag "Save", :name =>
'save_button', :disable_with => "..."
%>
<%= submit_tag "Preview", :name =>
'preview_button' %>
Controller:
def save
# Save button gets disabled when pressed, so no save
button means
preview...
if ! params['save_button'].nil? then
do_preview
else
do_save
end
end
derek.haynes wrote:
> I've run across a problem when attempting to submit a
form with the
> form_remote_tag when the form contains multiple submit
buttons.
>
> My form contains 2 submit buttons, a
"Preview" button and a "Post
> Message" button:
> <%= submit_tag 'Preview' %>
> <%= submit_tag 'Post Message' %>
>
> When the form is submitted, the value of params['commit'] is the
> value of the first submit tag ('Preview' in this case)
no matter what
> button is used to submit the form.
>
> This is not present when changing the form to a
standard non-ajax form.
>
> Any one else run across this problem or have a
suggested fix?
>
>
> --
> Derek Haynes
> HighGroove Studios - http://www.highgroove.com
a>
> Atlanta, GA
> Keeping it Simple.
> 404.593.4879
--
Posted via http://www.ruby-forum.com
/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
|