mbhattacharyanetwoven

Validating Attachment control by using custom function used as a rule inside a form

Blog Post created by mbhattacharyanetwoven on Aug 19, 2017

Many times we have to validate attachment control inside a form on certain condition. For example, say, there is a checkbox on a form and when you check the checkbox you need to add an attachment (Mandatory) otherwise not. So how you will accomplish this? It's easy and here are the steps to follow:

 

  1. Create a custom function to check the named attachment is whether having a minimum attachment attached to it or not.
  2. Create a rule using that custom function where you have to pass the CSS class name of the attachment as a parameter to that custom function.

 

Follow the section below for detailed implementation:

 

The screen looks like as follows:

 

Now if you check the AttachmentFlag, it’s mandatory to attach attachments. For that follow the following steps:

 


 

Step 1:

Goto NINTEX Forms -> Settings -> Custom Javascript and write the following function CountAttachments

function CountAttachments(cssClassNameOfTheAttachment){ 

    return NWF.FormFiller.Attachments.GetAttachedFilesCount(NWF.FormFiller.Functions.GetFillerDivObjectForControl(NWF$("#"+NWF$("." + cssClassNameOfTheAttachment + " .nf-attachmentsRow")[0].id)).data('controlid'));

 }

as follows:

 

Step 2:

Select the attachment control and configure the CSS Class of it as follows:

Step 3:

Configure the name of the ‘Yes/No’ field (AttachmentFlag) as follows:

 

Step 4:

Now add a rule selecting the attachment control as follows:

N.B. Remember you have to pass the CSS class name of the Attachment control as a parameter inside the function CountAttachments().

Now when you submit the form checking the AttachmentFlag and without attaching any attachment the following messages will be displayed:

 

Hope this small blog will be helpful to you to validate any attachment control on demand. Thanks for viewing the blog!

Outcomes