How can I validate a field based of the attachment control?

  • 28 December 2016
  • 9 replies
  • 11 views

Badge +2

I have a last name field and I want to add a validation that if  it is empty AND the form has no attachments, then it is invalid.  In other words either the last name needs to be filled or the form needs an attachment.....I can't get anything to validate against the attachment control. Any ideas?


9 replies

Userlevel 5
Badge +14

have a look eg. here https://community.nintex.com/message/42744?commentID=42744#comment-42747 

Badge +2

Thanks, I think this may work...=) Will try and let you know later.

Badge +2

Sorry I can 't get it to work. Not sure how to use it in junction with the isNullorEmpty. Also, which control would I use to invoke the function? If I add it to last name control, nothing validates on the form. 

Userlevel 5
Badge +14

hard to say what are you doing wrong, you should post more details what exactly you are doing and what doesn't work.

check as well whether you aren't experiencing any errors in developer console

in general you should

- copy javascript code from link I provided into form settings/custom javascript

- create a validation rule with formula like this one and attach it to a control you want to get highlighted once validation fails

isNullOrEmpty(LastName) && GetNumberOfAttachments("AttachmentControlClass") < 1

- make sure you  configured 'AttachmentControlClass' CSS class (without quotes) to attachment control.

Badge +2

Marian Hatala

I am trying to follow this and I am just not seeing the result like I would think I should. It's got to be something I am doing wrong... I am using

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

for my javascript and I have  a choice field that I am trying to validate against when it results in "Fixed Assets"

I have set my attachment control CSS class to both attCtrlClassName and to AttachmentControlClass along with a validation rule of 

Disposal Type == 'Fixed Assets' &&GetNumberOfAttachments("attCtrlClassName") < 1

anyways the form allows me to submit regardless of attachment... I am also attaching screenshots that may help show my error.. Thanks I know your busy and appreciate any feedback...

Pic of JavascriptValidation Rule

Userlevel 5
Badge +14

attachment control's CSS class you configure in setting dialog has to be input parameter to the GetNumberOfAttachments() function

so based on your screenshots, your formula should look like this

Disposal Type == 'Fixed Assets' && GetNumberOfAttachments("AttachmentControlClass") < 1

I've briefly looked on your xml and have found an instance of GetNumberOfAttachments with correct classname but with missing openning apostrophe, so this was likely your issue.

Userlevel 5
Badge +14

Hi ‌,

were you able to resolve your issue?

if so could you close the question and select correct answer?

#BRGreview

Badge +2

Thank You... That didn't seem to work so I must have something else wrong. I will try working on it a little more

Badge +2

I could not get it to work but ended up validating on the last name field instead with a custom validation:

function AttachmentNotNeeded(source, arguments)
{
  var attachCount= GetNumberOfAttachments('nf-form-input-attachment');
  var lastName=NWF$('#' + varLastName).val();
  
  if(lastName=='' && attachCount<1)
  {
    arguments.IsValid=false;
  }
  else
  {arguments.IsValid=true;}

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

Thanks for your help though. =)

Reply