merru
Nintex Newbie

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

Jump to solution

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?

0 Kudos
Reply
9 Replies
emha
Automation Master
Automation Master

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

Jump to solution
0 Kudos
Reply
merru
Nintex Newbie

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

Jump to solution

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

Reply
merru
Nintex Newbie

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

Jump to solution

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. 

0 Kudos
Reply
emha
Automation Master
Automation Master

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

Jump to solution

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.

0 Kudos
Reply
jpayne
Nintex Newbie

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

Jump to solution

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

0 Kudos
Reply
emha
Automation Master
Automation Master

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

Jump to solution

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.

Reply
emha
Automation Master
Automation Master

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

Jump to solution

Hi ‌,

were you able to resolve your issue?

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

#BRGreview

0 Kudos
Reply
jpayne
Nintex Newbie

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

Jump to solution

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

0 Kudos
Reply
merru
Nintex Newbie

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

Jump to solution

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. 😃

View solution in original post

Reply