Reputation: 72
When user add a file into queue I must validate so I wrote a function in callback:
$(document).ready( function() {
$('#fileupload').bind('fileuploadadd', function (e, data) {
$.each(data.files, function (index, file) {
check = ValidaDoc(file.name);
if (check!="OK"){
var erro="";
if (check=="Alerta1"){
alert("Alerta1");
}
else {
errotemp="";
if(check=="Erro1"){erro=erro + file.name + " com extensão não esperada.";}
else if(check=="Erro2"){erro=erro + file.name + " não cadastrado ou com nome fora do padrão.";}
$($('#fileupload .files .cancel button')[index]).click();
}
}
});
});
The callback works, the ValidaDoc function works and a file is canceled but not the right one. I think the index use is no right. Anyone have a ideia?
Upvotes: 1
Views: 1416
Reputation: 72
The problem was my misunderstaning of the index. I replace the line that calls click with the one bellow and all works fine.
$($('#fileupload .files .cancel button')[data.context[index].rowIndex]).click();
I have to change the event too. When the fileuploadadd is called the file is not in the table yet. So changed to fileuploadded.
$('#fileupload').bind('fileuploadadded', function (e, data) {
Upvotes: 2