Cannot get Attachment Validation to Work

  • 14 December 2017
  • 7 replies
  • 11 views

Badge +3

I've been following this article on how to conditionally require an attachment on a Nintex form and I haven't had any luck getting it to work.  I suspect, because I'm no expert on JavaScript, I've somehow modified the code incorrectly.

What I am trying to do is that if the Status field is set to "Completed" then there must be a minimum of two attachments. I should also explain that the Status field is a drop-down containing a selection of "Completed" along with "Not Started" and "In Process".

Thanks for your assistance.

  1. function validateAttachments(source, arguments)
  2. {
  3. var elm = NWF$(‘.nf-attachmentsTable’);
  4. var statusValue = NWF$(‘#’ + StatusClientID).val();
  5. arguments.IsValid = true;if (statusValue == ‘Completed’) {
  6. if (elm.length > 0 && elm.find(‘tr’).length >= 2) {
  7. arguments.IsValid = true;
  8. } else {
  9. arguments.IsValid = false;
  10. }}}

Status field config


7 replies

Userlevel 5
Badge +14

have a look on this https://community.nintex.com/message/48663-re-can-you-validate-the-minimum-attachments-as-a-condition?commentID=48663#co… 

Badge +3

Thank you; however, I cannot seem to get this to work.  Also, I've test this below and created a variable and then referenced this variable within a calculated field I've placed on the form to see what it would render during runtime and it's not returning anything:

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

Here's how I implemented it just in case I've missed something:

Form Setting JavaScript

Attachment CSS class

Status Field Validation Rule Formula

Userlevel 5
Badge +14

Check usage of GetNumberOfAttachments function carefully.

you have supplied wrong selector as its input parameter, it should have been "attCtrlClassName" which you have configured as 'CSS Class' for attachment control, instead of 'nf-form-input'

Badge +3

I've made the correction and it still does not work:

Status=="Completed" && (GetNumberOfAttachments("attCtrlClassName") <1)

I've also attached the actual form.

Thanks again for the help.

Userlevel 5
Badge +14

it looks like you are on forms 2010, I've tested the script on 2013...

can you check developer console whether you do not get reported any errors there?

Badge +3

Developer's console?  You mean within the web browser?

Userlevel 5
Badge +14

yes, in browser. - press F12, run the form and check console for errors.

Reply