Skip to content

Commit 1ba7479

Browse files
authored
Check attchment type and count files attached on Catalog Form (#2581)
* Add file attachment validation script An onSubmit Client script that checks for file attachment criteria. * Add file type validation for attachments on submit
1 parent 81b587d commit 1ba7479

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Check Attachment

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
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.
2+
3+
Note: Check this property - glide.attachment.extensions

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)