1

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?

1
  • Think I got it. This index is for $,each function not the files order in table. So I rewrite the click to:"$($('#fileupload .files .cancel button')[data.context[index].rowIndex]).click();" Commented Apr 23, 2012 at 10:59

1 Answer 1

2

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) {
Sign up to request clarification or add additional context in comments.

1 Comment

I've been looking for this for hours - you rock!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.