0
I have the following code on the form:
   <div class="form-group ">
            <small id="small-alert-pic">Máximo de 7 fotos</small>
            <small id="picture-size"></small>
            <input type="file" name="files[]" class="form-control"
            multiple="multiple" placeholder="" id="picture">
   </div>
When I perform the selection of the files I have the quantity validation( that works normally ):
    $("#picture").on("change", function () {
        if ($("#picture")[0].files.length > 7) {
            $(this).css('boder', '3px solid red');
            $('#small-alert-pic').css('color', 'red')
            $('#small-alert-pic').text('ATENÇÃO! SÃO PERMITIDOS APENAS 7 FOTOS PARA UPLOAD');
        }
    });
however when I do the file size validation occurs it only validates the first one. If I select a file of 1kb and one of 19MB( in this order) it does not validate the second, however if I select the 19MB and the 1KB it validates normally. Follows the code:
 $('#picture').change(function(){
        var isOk = true;
        var maxSize = parseInt(2048, 10)
        $('input[type=file]').each(function () {
            if (typeof this.files[0] !== 'undefined') {
                var size = this.files[0].size;
                console.log(size / 1000 + ' -- ' + maxSize);
                isOk = maxSize > (size / 1000);
                if (!isOk) {
                    $('#picture-size').prev().css({
                        "color": " red"
                    }).text('ATENÇÃO SÃO PERMITIDOS CADA ARQUIVO DEVE POSSUIR APENAS 2MB');
                } else {
                    $(this).prev().css({
                        "border": "none"
                    });
                }
                return isOk;
            }
        });
        return isOk;
    });
Does anyone have any idea what might be going on?
The looping worked now, I had to make some modifications because when the Return is placed inside each it only runs the first. Thank you.
– Betini O. Heleno
On time, my friend.
– Taffarel Xavier