I am attempting to setup validation for a file upload. I am already using jquery validate for other inputs in my form (not shown here for simplicity), so I wanted to continue to use this method for consistency.
I am struggling getting it to work because the name field in my file input has brackets for an array to upload multiple attachments. Thefore, I am running into one of two issues:
I put in the actual name in the jquery rule
uploadedFile[]and then I get an error.I take the brackets off and just have
uploadedFile, but then this field isn't recognized and the validation doesn't work.
The most logical thing to me is to use the id. I cannot find a good method based on everything I have searched.
Is there a way to run this using the id for uploadedFile[] or is there a different, more effective way of doing this?
Input
<input type="file" name="uploadedFile[]" class="inputfile" id="uploadedFileTest" data-multiple-caption="{count} files selected" multiple>
JS
$('#shareProjectForm').validate({
ignore: [],
rules: {
uploadedFile: {
required: true,
extension: 'png|jpg|jpeg|pdf|gif'
}
},
messages: {
uploadedFile: {
required: "A file must be uploaded",
extension: "You must choose a file with one of the following formats: .png, .jpg, .jpeg, .pdf or .gif"
}
},