-
-
Save mivanek/f37fc734a30106760ff5 to your computer and use it in GitHub Desktop.
jquery-file-upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for [@project, attachment], :html => {:id=>"fileupload", :class => type } do |f| %> | |
<%= hidden_field_tag 'attachment_type', type %> | |
<%= hidden_field_tag 'project_id', project_id %> | |
<span class="file-upload button"> | |
<span>Attach a File</span> | |
<%= f.file_field :path %> | |
</span> | |
<table id="results"><tbody class="files"></tbody></table> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
// Initialize the jQuery File Upload widget: | |
$('#fileupload.<%= type %>').fileupload({ | |
autoUpload: true, | |
dataType: 'json' | |
}).bind('fileuploadalways', function (e, data) { | |
window.showQuickForm(); | |
}).bind('fileuploadcompleted', function (e, data) { | |
// the current variable points to the hidden field that is used in | |
// the issues form to send relevant data to the issues create action | |
var current = $("<%= field_id %> input#attach_list").attr("value"); | |
$.each(data.result, function (index, file) { | |
// if the field is empty, set the value of the field to the uploaded's file name | |
if (current =="") { | |
current = file.id; | |
} else { | |
// if it's not empty, append the file name to the already existing values | |
current += "," + file.id; | |
} | |
}); | |
$("<%= field_id %> input#attach_list").attr("value", current); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment