Not applicable

Attachment Validation based on checkbox in a Multiple attachment form

Hello All,

I have multiple attachments in different sections in my Nintex form and I am validating only one attachment in one section

which is based on a Checkbox and if it is checked, there need to be a minimum of 1 attachment on the form.

I tried the below javascript code ,since there are multiple attachments ,javascript cannot identify which attachment is to validate,Can anyone help me with a solution?

Thanks in advance!

Javasript Code :

function fnAttachmentValidation(source, arguments)

{

      var Control = NWF$("#" + varMyCheckBoxID);

      var elm = NWF$("table[id*=idAttachmentsTable]");     

      var elmAttachmentRow = NWF$("div[id*=idAttachmentsRow]");

 

      if(Control.is(':checked') == true)

      {  // minimum one attachment is required

          if ((elm != null && elm.prop('rows').length > 0) && (elmAttachmentRow != null))

          {

             arguments.IsValid = true;

          }

          else

          {

             arguments.IsValid = false;

          }

      }

}

Reply
8 Replies
andrewg
Automation Master
Automation Master

Re: Attachment Validation based on checkbox in a Multiple attachment form

You may not have the right DIV element that you are setting the isValid on?

I did this in a non validated way, but used rules to show red text that an attachment was required when a condition was met. You can also disable the submit button with the same rules to force the user to add the attachment. Could this work in your scenario?

Euan Gamble‌, I think if Preetha was able to use Named Controls in the attachment control validation formula, then she wouldn't need JS for the validation. Here is a good use case for that. 

Reply
emha
Automation Master
Automation Master

Re: Attachment Validation based on checkbox in a Multiple attachment form

you can configure a custom CSS class to respective attachment control.

then you can use that class as a selector in js code to directly reference the control.

Reply
Not applicable

Re: Attachment Validation based on checkbox in a Multiple attachment form

Thanks for the Reply Andrew..Initially I tried to disable the button but ended up in error for some reason,there is a system generated document number in the form which was not functioning when I apply this rule.

Reply
Not applicable

Re: Attachment Validation based on checkbox in a Multiple attachment form

Thank you Marian,I will try with the CSS class.

Reply
Not applicable

Re: Attachment Validation based on checkbox in a Multiple attachment form

Hello All,

My issue got resolved finally.I am providing the solution below as it may be helpful to others also.

Added below code in 'Minimum attachment field' in the attachment control settings.

fn-If(fn-Equals(Phase,'Security Update'), 1,0)

Added below code in JavaScript:

function ValidateUpdatesCompleted(source, arguments)
{
var txtPhaseValue = NWF$('#' + vartxtPhase);
if(txtPhaseValue.val() == "Security Update")
{
if(NWF$('#' + Secupdate).prop('checked'))
{
arguments.IsValid=true;
}
else
{
arguments.IsValid=false;
}
}
};

Reply
emha
Automation Master
Automation Master

Re: Attachment Validation based on checkbox in a Multiple attachment form

are you sure it really works?

can you post screenshot of attachment control configuration?

as for fn-If(...): "Phase" has to be item's field in that case. so you effectively check what's already stored in list item and not what phase/section is currently selected on the form. this as well means the formula can not work in NEW form at all.

if that's your target then ok.

as for the javascript function: it only check state of control's referenced by variables vartxtPhase and Secupdate. it doesn't reflect content of attachment control at all. so once first if evaluates to true and second one to false the control will not pass validation, regardless of whether you supplied any attachment(s) or not.

so I'm quite confused how could it align with your original requirement...

0 Kudos
Reply
Not applicable

Re: Attachment Validation based on checkbox in a Multiple attachment form

It works fine with my requirement that is why i thought of sharing the solution with all.

it validates in two ways,user has to check the checkbox and minimum one attachment in the attachment control as well.

When I try to save the form without selecting the checkbox and attachment I get the below validation error.

As you said the security Update is a phase ,I am validating this section only on the security update phase.

0 Kudos
Reply
andrewg
Automation Master
Automation Master

Re: Attachment Validation based on checkbox in a Multiple attachment form

Marian Hatala‌ is right, that the formula is not actually checking the control's value at the time, but he list item's previous value as the form is opened. It may work in one scenario, but not all possible. This ability to use named controls in in User Voice at Ability to validate attachment controls – Customer Feedback for Nintex  and currently marked Planned. With that ability, you will be able to do it without javascript. 

Reply