Skip to content

Commit 795a4ce

Browse files
authored
Add file type validation for attachments on submit
1 parent f9e284f commit 795a4ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

CheckAttachmentFiletypr.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function onSubmit() {
2+
var arr = [];
3+
var extension1 = '.txt';
4+
var extension2 = '.pdf';
5+
var extension3 = '.docx';
6+
var names = this.document.getElementsByClassName('get-attachment ng-binding ng-scope');
7+
for (var i = 0; i < names.length; i++) {
8+
var val = names[i].innerHTML;
9+
arr.push(val.toString());
10+
}
11+
12+
var countRequired = 1;
13+
if (window == null) {
14+
if (this.document.getElementsByClassName('get-attachment').length != countRequired) {
15+
g_form.addErrorMessage('You can add only one attachment');
16+
return false;
17+
}
18+
}
19+
20+
for (var j = 0; j < arr.length; j++) {
21+
if ((arr[j].indexOf(extension1) > -1) || (arr[j].indexOf(extension2) > -1) || (arr[j].indexOf(extension3) > -1)) {
22+
return true;
23+
} else {
24+
g_form.addErrorMessage('Unsupported file format. Please attach files with extensions .txt, .pdf, .doc');
25+
return false;
26+
}
27+
28+
}
29+
30+
}

0 commit comments

Comments
 (0)