I have a rails project that is using the refile gem to process file uploading, and I would like to submit a form after the user has selected the file in their file browser.
I created a button in the navbar of the rails app, and have the following form.
_nav.html.erb
<div class='upload-image'>
<form name="form_upload_image">
<p>Upload Image <i class="fa fa-upload"></i></p>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |form| %>
<%= form.attachment_field :tshirt_image, direct: true, class: "fa fa-upload", input_html: { hidden: true, onchange: "uploadImage()" } %>
<%= form.submit "Update", class: "btn btn-primary" %>
<% end %> <!-- form -->
</form>
</div>
I would like to call the uploadImage JS function once the user has selected the Open button within the file browser.
I created a navbar_image_upload.js file within the app/assets/javascripts which looks like the following,
// app/assets/javascripts/navbar_image_upload.js
function uploadImage() {
document.forms["form_upload_image"].submit();
}
However, when I select the file in the file browser and choose Open it's not submitting the form. Any help would be appreciated.