How can i change the default error message of the jquery validation?
here is my html form:
<form id="form_detail_file3" action="{$form_action}" method="POST" enctype='multipart/form-data'>
<div >
<label for="file" >Inserisci il documento:</label>
<input type="file" accept="image/png, image/gif, image/jpeg" name="fileToUpload"
id="fileToUpload">
</div>
</form>
And JS:
$("#form_detail_file3").validate({
rules: {
fileToUpload: {
required: true,
extension: "jpg|jpeg|png|ico|bmp"
}
},
messages: {
fileToUpload: {
required: "Please upload file.",
extension: "Please upload file in these format only (jpg, jpeg, png, ico, bmp)."
}
}
});
The code is working and i get require message when there is no file to upload ,however if the extention that provided is not mached it show this default message "Please enter a value with a valid mimetype.".
CodePudding user response:
if extension is not matched it shows "Please enter a value with a valid mimetype."
Mimetype has nothing to do with file extension, therefore this cannot be the default message from the extension
rule.
"enter valid mimetype"
is the default error message from the accept
rule, which validates mimetype, and that you have declared inline with your HTML markup here:
<input type="file" accept="image/png, image/gif, image/jpeg" name="fileToUpload" ....
This plugin is easier to use and understand when you declare all rules using one consistent method, rather than mixing inline HTML5 rules with your jQuery .validate()
rules
.
The jQuery Validate plugin automatically converts various inline declarations into rules, such as HTML5 and certain class names.
Example: Inline required="required"
or will do the same thing as
required: true
inside rules
option of .validate()
.