1
I am trying to use jQuery Validate plugin to validate a field file
.
I just want to check the image size. If it is larger than 3mb it is not to submit the form.
Look at my code below:
$.validator.addMethod('filesize', function(value, element, param) {
return this.optional(element) || (element.files[0].size >= param)
});
if($("#form-ouvidoria")[0]){
$("#form-ouvidoria").validate({
rules : {
assunto : "required",
departamento : "required",
mensagem : "required",
field: {
required: true,
extension: "png|jpe?g|gif",
filesize: 3145728
}
},
submitHandler: function(form){
$("#enviaChamado").attr('disabled', 'true');
$('span.loading').css('opacity', '1');
form.submit();
}
});
}
But when selecting an image larger than 3mb and pressing on send gives the following error:
Uncaught Typeerror: Cannot read Property 'call' of Undefined. Exception occurred when checking element , check the 'Extension' method.
What kind of application "IDE" you are using?
– Marco Souza
Like this, @Marconciliosouza ?
– Diego Souza
Your
jQuery
, you’re using on a pageaspx
,php
...html
.....– Marco Souza
And what the server-side language influences in this ?
– Diego Souza
I had no influence on the answer, it was only a doubt of mine... but as you already have the answer blz.
– Marco Souza
It’s in PHP that I program.
– Diego Souza