mardi 4 août 2015

RoR: jquery file upload on submit form button

How do I make it so my submit button will upload the images?

<%= simple_form_for @project, html: { multipart: true, id: 'fileupload' } do |f| %>

  <span class="btn btn-success fileinput-button">
    <i class="glyphicon glyphicon-plus"></i>
    <span>Add files...</span>
    <input type="file" name="photos[]" id='photo_upload_btn', multiple>
  </span>
  <button type="submit" class="btn btn-primary start">
    <i class="glyphicon glyphicon-upload"></i>
    <span>Start upload</span>
  </button>
  <button type="reset" class="btn btn-warning cancel">
    <i class="glyphicon glyphicon-ban-circle"></i>
    <span>Cancel upload</span>
  </button>

  <%= f.button :submit, class: "btn btn-primary pull-right" %>
<% end %>


<script>
$(function () {

'use strict'; //not even sure what this is for

$('#fileupload').fileupload({

});
    // Load existing files:
    $('#fileupload').addClass('fileupload-processing');
    $.ajax({
        url: $('#fileupload').fileupload('option', 'url'),
        dataType: 'json',
        context: $('#fileupload')[0]
    }).always(function () {
        $(this).removeClass('fileupload-processing');
    }).done(function (result) {
        $(this).fileupload('option', 'done')
            .call(this, $.Event('done'), {result: result});
    });
});
</script>

Right now, when I upload an image, it'll show thumbnail preview and start button with a cancel button. I want to move the start button and have it all upload using the submit button.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire