Test custom file upload

This commit is contained in:
Brian Federle 2015-01-06 13:51:37 -08:00
parent 70fe283b67
commit a36d2191ec
1 changed files with 57 additions and 8 deletions

View File

@ -476,9 +476,13 @@
} else if (field.isFileUpload) {
$input = $('<input>').attr({
type: 'file',
name: 'files[]',
'data-url': '/upload.jsp'
name: 'files[]'
}).appendTo($value);
// Add events
$input.change(function(event) {
$form.data('files', event.target.files);
});
} else if (field.isTokenInput) { // jquery.tokeninput.js
isAsync = true;
@ -678,12 +682,57 @@
}
}
args.after({
data: data,
ref: args.ref, // For backwards compatibility; use context
context: args.context,
$form: $form
});
var uploadFiles = function() {
// START A LOADING SPINNER HERE
// Create a formdata object and add the files
var data = new FormData();
$.each($form.data('files'), function(key, value)
{
data.append(key, value);
});
$.ajax({
url: '/client/upload.json',
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function(data, textStatus, jqXHR)
{
if(typeof data.error === 'undefined')
{
// Success so call function to process the form
debugger;
//submitForm(event, data);
}
else
{
// Handle errors here
console.log('ERRORS: ' + data.error);
}
},
error: function(jqXHR, textStatus, errorThrown)
{
// Handle errors here
console.log('ERRORS: ' + textStatus);
// STOP LOADING SPINNER
}
});
};
if ($form.data('files')) {
uploadFiles();
} else {
args.after({
data: data,
ref: args.ref, // For backwards compatibility; use context
context: args.context,
$form: $form
});
}
return true;
};