Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Check Attachment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
An onSubmit Client script that checks whether only one file is attached and also file type should be .doc, .pdf or .txt. Otherwise form will not be submitted and required error message will be displayed to user.

Note: Check this property - glide.attachment.extensions
30 changes: 30 additions & 0 deletions CheckAttachmentFiletypr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function onSubmit() {
var arr = [];
var extension1 = '.txt';
var extension2 = '.pdf';
var extension3 = '.docx';
var names = this.document.getElementsByClassName('get-attachment ng-binding ng-scope');
for (var i = 0; i < names.length; i++) {
var val = names[i].innerHTML;
arr.push(val.toString());
}

var countRequired = 1;
if (window == null) {
if (this.document.getElementsByClassName('get-attachment').length != countRequired) {
g_form.addErrorMessage('You can add only one attachment');
return false;
}
}

for (var j = 0; j < arr.length; j++) {
if ((arr[j].indexOf(extension1) > -1) || (arr[j].indexOf(extension2) > -1) || (arr[j].indexOf(extension3) > -1)) {
return true;
} else {
g_form.addErrorMessage('Unsupported file format. Please attach files with extensions .txt, .pdf, .doc');
return false;
}

}

}
Loading