Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails disable remote form submit

I have a form that I want to submit through AJAX most of the time. However, there's also multiple file fields in the form. Whenever a file is submitted I need to temporarily disable AJAX-functionality so that the file can be processed.

I tried removing the data-remote attribute, but of course that's not enough because jQuery already binds the AJAX function to the form. How do I unbind it?

Edit:

Oh wow, I'm so stupid. Rails does this by default. I hadn't even tried it yet. Sorry for polluting StackExchange.

like image 560
Bram Jetten Avatar asked Mar 21 '26 23:03

Bram Jetten


2 Answers

Why don't you simply remove the data-remote attribute. If you are using jquery it would look something like this:

$("#element").removeAttr("data-remote");
like image 91
chuck w Avatar answered Mar 24 '26 13:03

chuck w


You can use :disable_with option like

<%= submit_tag 'Submit', :disable_with => 'Please wait..' %>
like image 40
DeathHammer Avatar answered Mar 24 '26 12:03

DeathHammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!