Reputation: 2415
Im using this awesome plugins
This is my success scenario:
And this is my error scenarion:
It seems that the delete button on each thumbnail deleting all files instead their current thumbnail. What's wrong?
this is my script:
var ids = $('#product-images-id').data('ids'); // use to initialize data in edit
if (ids) {
ids = ids.map(function(v) {
return eval('(' + v + ')');
});
$('#input-file').fileinput({
initialPreview: $('#product-images').data('images'),
initialPreviewConfig: ids,
overwriteInitial: false,
showUpload: false,
initialPreviewShowDelete: true,
showUploadedThumbs: true,
browseIcon: '<i class="fa fa-folder-open"></i> ',
removeIcon: '<i class="fa fa-trash-o"></i> ',
uploadUrl: "/file-upload-batch/2",
previewFileIcon: '<i class="fa fa-file"></i>',
layoutTemplates: {
actions: '<div class="file-actions">\n' +
' <div class="file-footer-buttons" style="float:none">\n' +
' {upload}{delete}{other}' +
' </div>\n' +
'</div>',
actionDelete: '<button type="button" class="kv-file-remove btn btn-danger btn-block" {dataUrl}{dataKey}><i class="fa fa-trash-o"></i> Delete</button>',
actionUpload: '',
},
previewTemplates: {
image: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
' <img src="{data}" class="file-preview-image" title="{caption}" alt="{caption}" style="width: 200px;height: 113px;">\n' +
' {footer}\n' +
'</div>\n',
}
});
}
I've been facing this issue for 3 days and not yet solved. Please help, thanks in advance
Upvotes: 0
Views: 8329
Reputation: 139
You must use the uploadUrl to save the files and the rest of the form data via AJAX. So instead of submitting the form you should use uploadExtraData in the options and trigger the upload event. Something like this:
var ids = $('#product-images-id').data('ids'); // use to initialize data in edit
if (ids) {
ids = ids.map(function(v) {
return eval('(' + v + ')');
});
$('#input-file').fileinput({
initialPreview: $('#product-images').data('images'),
initialPreviewConfig: ids,
overwriteInitial: false,
showUpload: false,
initialPreviewShowDelete: true,
showUploadedThumbs: true,
browseIcon: '<i class="fa fa-folder-open"></i> ',
removeIcon: '<i class="fa fa-trash-o"></i> ',
uploadUrl: "/file-upload-batch/2",
previewFileIcon: '<i class="fa fa-file"></i>',
layoutTemplates: {
actions: '<div class="file-actions">\n' +
' <div class="file-footer-buttons" style="float:none">\n' +
' {upload}{delete}{other}' +
' </div>\n' +
'</div>',
actionDelete: '<button type="button" class="kv-file-remove btn btn-danger btn-block" {dataUrl}{dataKey}><i class="fa fa-trash-o"></i> Delete</button>',
actionUpload: '',
},
previewTemplates: {
image: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
' <img src="{data}" class="file-preview-image" title="{caption}" alt="{caption}" style="width: 200px;height: 113px;">\n' +
' {footer}\n' +
'</div>\n',
},
uploadExtraData : function (previewId, index) {
var obj = {};
$('#form-id').find('input,select').each(function() {
var id = $(this).attr('name'), val = $(this).val();
obj[id] = val;
});
return obj;
}
});
}
$('#form-id').submit(function(event) {
event.preventDefault();
$('#input-file').fileinput('upload');
});
Upvotes: 1