views:

613

answers:

2

Hi all,

I know how to add javascript code to an onclick event of a button eg: <%= submit_tag 'Enter', :onclick => "this.disabled=true,this.form.submit();" %>

I wonder if I can use rjs in the onclick. I want to use it to render out a partial.

Thanks, Stijn

+2  A: 

Check documentation for *remote_form_for* and *submit_to_remote*. Your JS code to disable the form you can pass as :loading option. You can also pass code to activate the form as :complete option.

Above functions generate JS code which uses onsubmit event but the behavior will be the same.

Greg Dan
+1  A: 

In case that you really need to generate java script from rjs with in submit button. You can add rjs directly to .html.erb file like this

<%= submit_tag 'Enter', 
  :onclick => render(:update) { |page| 
      page[:enter].disable
    }, 
  :id => 'enter' %>

but If you just only need to render partial. The answer from Greg Dan is better.

Bank