How to create a button with a file upload action
I've got a form where the user is allowed to import a spreadsheet. Currently the part for the user to select the file looks like:
<%= form_tag import_clearance_crews_path(@clearance), multipart: true, class: "ui form" do %> <%= file_field_tag :file, class: "ui button green" %> <%= submit_tag "Import", class: "ui button" %> <% end %>
Which works ok, on clicking 'choose file' the user is allowed to pick up a file and then he needs to click 'import' to finalize the import...
I was wondering if there is a way to just have a button, once you click on it you can pick up a file and straight after selecting it just upload and redirect to X view?
You should be able to listen to the
change event on the file field. That fires anytime the input value changes. Use that to fire off the form submit.