简体   繁体   中英

Why do I lose trace of the submit button when I post a form with a file_field

I have a form in my rails app which posts a (invoice) number, amount, date and file to a controller. I have a submit button with a name attribute, let's say "submit" .

If I post the form without the file_field , the params in the controller contain a key "submit" , but when I include the file_field it disappears.

I'm not intercepting the form submission in any way. What could be going on here?

Edit - Basically the form looks like this:

<%= form_tag({:controller => 'controller', :action => :update}, {:remote => true, :multipart => true}) do |form| %>

    <%= form.text_field(:date) %>
    <%= form.text_field(:amount) %>
    <%= form.text_field(:number) %>
    <%= form.file_field(:file_upload) %>

    <%= form.submit 'Save', :name => "submit" %>
<% end %>

Figured it out. It so happens that I have code to disable submit buttons during a post. When the file_field is included in the post params the form processing takes longer and by the time the form is actually processing the submit button it has been disabled. I'll have to find a different solution for this.

$body.on('submit', 'form[data-remote="true"] ', function() {
    var $railsUjsForm = $(this);
    $railsUjsForm.find('input[type="submit"]').prop('disabled', true);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM