Lennos
Canvas Initiate

Get classname of Attachment Control using JS

Hi,

I have multiple attachment control with in the form, does anyone know how to get the classname or name of attachment control using javascript?

 

Thanks in advance

0 Kudos
Reply
2 Replies
Tarf
Design Canvas Artiste

Re: Get classname of Attachment Control using JS

Hi,

 

I used the following js line in the console to display all the class names:

2020-04-06 07_37_19-Window.png

Please note how the second class differs for each element.

 

Maybe you can adapt this to your needs?

 

0 Kudos
Reply
Lennos
Canvas Initiate

Re: Get classname of Attachment Control using JS

It's working now but I have come up with this idea. it's bit similar to yours.
Steps:
1. adding unique name in css class field on each attachment control settings
2. adding validation rule on each attachment control and call the JS function below and supply that unique name in step 1


function IsAttachmentSizeExceeded(maxSizeInMB,cssClassNameOfTheAttachment ) {
var isValid=false;
var sizeInMB = 0;
var attachmentFiles='';
var attachmentSelector = '.'+cssClassNameOfTheAttachment +' input[type=file]';
var attCount=NWF$('.nf-attachmentsTable').find('tr').length;

for ( var i=0; i<NWF$(attachmentSelector).length; i++ ) {
attachmentFiles =NWF$(attachmentSelector)[i].files;
if(attachmentFiles.length>0 && attachmentFiles!==null && attachmentFiles[0]!==undefined) {
sizeInMB = sizeInMB+ Math.round(attachmentFiles[0].size / 10486) / 100; // # MB with two decimal places
}
}
if(sizeInMB>maxSizeInMB) {
isValid=true;
}

return isValid;
};

0 Kudos
Reply