October 4, 2006
Auto disabling the submit button with KRJS
Benjamin over at RubyOnRailsBlog was recently wondering about how to painlessly disable a submit button to prevent the user from hitting it multiple times.
This requires some sort of javascript hackery to achieve, but the easiest way I’ve found to do this is with my trusty old KRJS pocketknife.
-
# in application controller
-
-
def on_commit_click
-
render :update |page| do
-
page[‘commit’].disabled = true
-
page << "$(’commit’).form.submit();"
-
end
-
end
-
-
# in the form
-
-
<%= submit_tag ‘Submit’, :id=>’commit’ %>
This will add this behavior for all submit buttons with the ‘commit’ id. The hardest part here is remembering to add the ‘commit’ id.
Requires: KRJS Plugin
Filed by Kevin Olbrich at 8:52 pm under AJAX, Ruby on Rails, User Interface, plugins
4 Comments