Skip to main content

I have need for very custom validation on an attachment field.

We have a series of cascading drop down menus that make the attachment field visible based on the selections. When the conditions that make the attachments visible I want to require an attachment. When the attachments are not visible, I don't want attachments to be required.

Anyone have a good way to go about setting this up? I don't see any way to do this with any of the out of the box functions and validation doesn't seem to work with rules either. I put a real simple condition like "IsEmptyOrNull" in the conditional validation field, and if I open the form initially then click save that validation kicks off, invalidates the form and puts my custom error message up, but the moment I select one of the cascading drop down options, the form "refreshes" and when I try to save the form, the attachment validation passes (even though I have not attached anything).

Have you seen this? >>> Nintex Forms - Attachment Required - Vadim Tabakman


It does not cover conditional attachment validation only that it is required or not overall. Yes I have seen it.


I have written myself small javascript function that returns me number of attachemnets.


function GetNumberOfAttachments(attCtrlClassName){
   return NWF.FormFiller.Attachments.GetAttachedFilesCount(NWF.FormFiller.Functions.GetFillerDivObjectForControl(NWF$("#"+NWF$("." + attCtrlClassName + " .nf-attachmentsRow")n0].id)).data('controlid'))
}

then I simply use it in validation rules like

GetNumberOfAttachments("AttachmentControlClass") < 1

that allows me to combine it with other needed logic

attachments‌  custom validation‌ ‌ number of attachments‌


While this is nice, no where in my question did I ask for validation for the number of attachments. Where exactly are you going with this? I think this may be something you should put in a separate article or something as this is unrelated to my question.


you asked for:

When the conditions that make the attachments visible I want to require an attachment. When the attachments are not visible, I don't want attachments to be required.

number of attachments less than 1 means there is no attachment.

if you AND that with condition that makes your attachment control visible and place that combined condition into validation rule, once the control is visible and no attachment is included your form will not validate.

is it clear now?


Yes this makes more sense. I hadn't considered that method. Thanks for the clarification.


That's great, that's what I need!


Unfortunately I was not able to get this solution to work for me. I was out until recently due to surgery and I haven't been able to explore further options yet.


Just following up to see if the issue was resolved. It would help others if they can find the correct answer from this post.


Unfortunately the project was scrapped and worked on by another team so I was not able to implement any of this myself. I cannot validate the solution above works or not. Maybe someone else will use it and validate it.


solution has already been verified by several other threads happy.png

https://community.nintex.com/search.jspa?q=GetNumberOfAttachments 

#BRGreview


This is exactly what I'm looking to do. I have the script in form settings > custom js, but when I get no results from a form variable when I add the formula = GetNumberOfAttachments("attCtrl"). "attCtrl" is the class on each attachment control


sounds to be some different/specific problem.

I'd encourage you to start new question and describe full details of your setup, error(s) you get, etc.


 I have a attachment requirement condition on my form and attached a copy of my form if anyone wants to give it a try.

Step 1: Go into the form settings and paste this code below into the Custom JavaScript text box.

function GetNumberOfAttachments(attCtrlClassName){  
    return NWF.FormFiller.Attachments.GetAttachedFilesCount(NWF.FormFiller.Functions.GetFillerDivObjectForControl(NWF$("#"+NWF$("." + attCtrlClassName + " .nf-attachmentsRow")a0].id)).data('controlid'))
 } 

Step 2: Select the attachments control and create a validation rule like below on the attachments control.

RequestType == "New Badge or Name Change" && GetNumberOfAttachments("this is the CSS Class on the attachment control") <1

My Valadation Rule: RequestType == "New Badge or Name Change" && GetNumberOfAttachments("nf-form-input") <1


The solution works in a form list, but does not in task nintex form. This is my configuration:

Custom JS:

207422_pastedImage_1.png

Control:

207423_pastedImage_2.png

Rule:

207424_pastedImage_3.png


Hi Marian

It seems your function works for a form validation rule, but not a formatting (hide/disable) rule. I couldn't get it to work with the latter.

I need to hide a field for as long as GetNumberOfAttachments("AttachmentControlClass") < 1. How can we get this to work?


it doesn't matter whether you use the formula/script for formatting or validation rule. 

they are evaluated just the same way behind the scene.

check for other possible problems/errors on the form.


The code is definitely not working on hide/disable. It's completely ignored in fact.

Try adding the following to a control. You'll notice that the control remains hidden even after an attachment is uploaded. Time for a code fix, perhaps?

214046_pastedImage_1.png


ah, sorry. I haven't immediately realized attachment control is one of those which formatting rules (resp. runtime functions) are not supported for.

see documentation - https://help.nintex.com/en-US/nintex2013/help/#Forms/RootCategory/Designer/Nintex.Forms.FormulaBuilder.htm 


I'm just popping in to say that none of these formats worked for me, so I ended up taking the " < 1 " portion and calculating the number in a calculated field, then using that variable in the validation. Works well for my purposes. 


You have to make sure your CSS class name on the attachment control does not have a space in it and it will work wink.png


This is exactly what I needed for attachment validation. Thank you!!


Hey Marian Hatala‌ -- can you confirm if this should work in Repeating Section attachments, now that we have this as an option? I've your wonderful code work many times before but now trying it on a repeating section, I just keep returning "0" for attachment count.


I can confirm this answer with the explanation works perfectly on a custom list form. I did take a few minutes to actually test this out on a test site. The original answer's post is technically correct, but it did not provide the required details to achieve the objective where yours did. I was able to figure out how to unmark the other one and I have given the answer to you. Thank you. Sorry it took me nearly a year to do that. sad.png

Below is a screenshot of the proof of concept. You can see how I formatted on the right the conditions of the validation. I also had a formatting rule that hides the attachments field when the drop down shows "No". When in that condition, the attachments are not required:

216907_pastedImage_1.png

216929_pastedImage_2.png


You cannot add attachments into a repeating field. So unfortunately the answer to this is no. I just tested this out using the sample I posted above. I would imagine it works fine if you leave the attachments outside the repeating field if you follow the same guidelines as above.

216930_pastedImage_1.png

216931_pastedImage_1.png


Reply