Validating attachment field only if field is visible depending from a choice field


Badge +1

#validation #nintext form #attachment #visibility

I would like to add a validation to the attachment field but only if this field is visible. The field is only visible if a choice field is set for a selection field.

The attachment field is only visible if a choice field is set to a certain value (Created a rule for this):

I've also added a validation to this field that validates the number on at least one element:

1. Validation for Minimum attachments without expression:

In this case the problem is that even if the field is invisible the validation still works.

2. Validation with expression:

fn-If(fn-Equals(ShowAttachmentField,'Show'),1,0)

In this case, the validation does not work :-(

Someone has a suggestion or example how I can solve this problem?

Thank you for the help.


5 replies

Badge +11

Hi Cosimo Staffieri

The validation on the Minimum attachments field will work only if you already have the value in the Item Property: ShowAttachmentField

It does not give you an option to validate against the form variables.

You can combine the rules with JavaScript validation. See Marian's response on this post:  

Badge +1

Hi Kapil Joshi

Solved :-)

1.) Custom JavaScript added

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

     

2. )  Validation Rule created

   (ShowAttachmentField == "Show") && (GetNumberOfAttachments("nf-form-input") < 1)

  

Result

  1. If attachment control is not visible depending on the value "Not show" from control ShowAttachmentField, the validation is not active.
  2. If attachment control is visible depending on the value "Show" from control ShowAttachmentField, the validation is active.

   

   

Thank you for your help.

Best regards

Cosimo

Badge +11

Great work. Mark it as answered to help others on the community.

Userlevel 5
Badge +14

I'm glad you found my code useful happy.png

but I would strongly recommend to follow the source where you get it from into very details and define your own class for a attachment control.

nintex's native 'nf-form-input' class will identify too many controls on your form and will make it slower and/or cause undesired effects or even errors.

Badge +1

Hi Marian Hatala

Your code was very useful, I have now defined a new class for the Attachment Control.

Thank you for your help.

Reply