Skip to main content
Nintex Community Menu Bar

Get classname of Attachment Control using JS

  • April 3, 2020
  • 2 replies
  • 8 views

Forum|alt.badge.img+2

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

2 replies

Forum|alt.badge.img+8
  • Novice
  • April 6, 2020

Hi,

 

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

7158i9D875F4CD6815605.png

Please note how the second class differs for each element.

 

Maybe you can adapt this to your needs?

 


Forum|alt.badge.img+2
  • Author
  • April 8, 2020

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;
};