Rails.js not preventing double submit
See original GitHub issueUsing form :remote and jquery-rails (1.0.14)
You can easily double submit on firefox 6 and probably most other browsers. I worked around by adding code like this
$('#form').live('ajax:beforeSend', function(evt, xhr, settings){
// prevent double submit
$(':submit', this).click(function() {
return false;
});
});
Issue Analytics
- State:
- Created 12 years ago
- Comments:41 (13 by maintainers)
Top Results From Across the Web
In rails controllers, how to prevent double submit (when user ...
My rails app contain many forms (Ajaxified or not). To prevent users to submit twice or more some forms, I use Javascript. There's...
Read more >Prevent Double Data Submission in Rails - James Hibbard
The first I did was to use JavaScript to disable the submit button once it had been pressed. This is as simple as...
Read more >Javascript: prevent double form submission - The Art of Web
Using JavaScript to disable form buttons and prevent double submission of an online form. Presenting a 'please wait' message while the form ...
Read more >How to stop a user submitting the same data more than once
I have a standard form built with rails, which a user to my site can use to submit data. Unfortunately one user just...
Read more >Jquery – Prevent double submits in a Rails AJAX form
I tried adding this to the submit button itself – but it doesn't work. The button gets disabled, but no data is sent....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh wow, that’s strange. The only time I’ve seen this behavior was when someone was including the jquery-ujs file twice in their layout. If it’s doing that on its own, I’d definitely like to see an example.
I also encountered a problem like this - double form submission with a Rails 4 remote form. My problem wasn’t caused by double inclusion of jquery_ujs, it was caused by a javascript form validation library - https://github.com/jkaipr/bootstrap-validator-rails. I fixed it in the gem and informed the source code author about it - nghuuphuoc/bootstrapvalidator#319.
If you don’t have a double jquery_ujs and are experiencing this issue, I suggest you open up Chrome developer tools and look into the Network tab, there you have a column called Initiator - hovering over it will show you the stacktrace leading to the form submission. You should see two requests to the same URL, one of them initiated by jquery_ujs the other one probably by some other piece of javascript.
Hope this helps somebody.