I have a page in my web application where there is an option to upload a file. I am trying to validate if there is a file selected for upload, before submitting the form. I use jQuery form validator plugin for my form validations.
My html code for the file input tag is:
<div class="form-group">
<label for="exampleInputFile">New File</label>
<input type="file" id="file_add" name="file">
</div>
I am trying to check if there is any file selected using the following code:
$.formUtils.addValidator({
name : 'file_check',
validatorFunction : function(value, $el, config, language, $form)
{
if($('#addFile').val() == "")
return $('#file_add').val() == "" == 0;
},
errorMessage : 'Please choose a file',
errorMessageKey: 'notConfirmed'
});
But the form submission is still happening even if there is no file chosen for upload. Is there any way I can check if there is a file selected before the submission happens.....
Aucun commentaire:
Enregistrer un commentaire