With form_tag submit buttons I use the " :disable_with => ''button label while processing'' " option so that visitors with slow connections aren''t able to submit forms twice. How do I do the same thing with button_to? I''ve got several pages where there are multiple forms on the page being updated with Ajax so I can''t wrap the whole thing with a form_tag, and I can''t get button_to to take a :disable_with option. Any ideas? TIA, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/1d9f7c0f/attachment.html
On Monday, July 24, 2006, at 2:16 PM, Bill Walton wrote:>With form_tag submit buttons I use the " :disable_with => ''button >label while processing'' " option so that visitors with slow >connections aren''t able to submit forms twice. > >How do I do the same thing with button_to? > >I''ve got several pages where there are multiple forms on the page >being updated with Ajax so I can''t wrap the whole thing with a >form_tag, and I can''t get button_to to take a :disable_with option. > >Any ideas? > >TIA, >Bill > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails >What does your ''button_to'' call look like? You should be able to associate a JS function with the control so that it will disable the button when it is clicked. I imagine something like this... <%= button_to "destroy", {:controller=>''controller'', :action=>''action''}, {:id=>''destroy_button'', :onclick => "$(''destroy_button'').disabled = true;return false;"} %> Warning... not tested. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Hi Kevin, Kevin Olbrich wrote:> On Monday, July 24, 2006, at 2:16 PM, Bill Walton wrote: >>With form_tag submit buttons I use the " :disable_with => ''button >>label while processing'' " option so that visitors with slow >>connections aren''t able to submit forms twice. >> >>How do I do the same thing with button_to? > > What does your ''button_to'' call look like? > You should be able to associate a JS function with the control so that > it will disable the button when it is clicked.As usual, it turns our Rails makes it even easier than that ;-) When I looked at the documentation for the two I realized they took the same arguments. Well... except that form_tag takes the :disable_with option and button_to doesn''t. So I just substituted an empty form with the submit button styled the same way I had the button_to styled. NOTE: This works fine in the situation I was in, where the button_to was simply taking the visitor to another page. I do have one situation where there are three buttons on the page, two of which do something but currently have render => :nothing in the controller, so I''m sure I''ll have to go to something like your suggestion to get one of those two buttons to refresh when the controller action is done. The other doesn''t need to be refreshed. Or maybe I just change the page a bit so I can use the above. Thanks for your response, though! Best regards, Bill