Attachment Validations and Minimums

  • 4 November 2014
  • 6 replies
  • 12 views

Badge +9

Related to the Nintex Forms for SharePoint 1.6 (only tested on SP2010).

 

Custom JavaScript attachment validation changes with the new version. This is still required if you only want to validate attachment based on a selection on the form (maybe, unless someone know how to enter a formula below)

 

// Run Validation on Attachments
function ValidateAttachment(source, arguments) {
      var Control = NWF$("#" + CtrlControl).val();
      var elm = NWF$("table[id*=idAttachmentsTable]");

 

     // PRE ATTACHMENT CONTROL CHANGE
           var elmAttachmentRow = NWF$("table[id*=idAttachmentsRow]");

      // POST ATTACHMENT CONTROL CHANGE

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


      if ((elm != null && elm.prop('rows').length > 0) && (elmAttachmentRow != null)) {
           arguments.IsValid = true;
      }
      else {
           if (Control == "Yes") {
           arguments.IsValid = false;
           alert("Attachment Required")
           }
      }
}

 

The above code is based on Nintex Forms - Attachment Required - Vadim Tabakman

-----------------------------------------------------------------------------------------------------------------------------------

 

New attachments control with Minimum Attachments. Works great but it seems it's either on or off, you can't base it on a form control selection.

 

Question: Is it possible to to have a formula in the Minimum Attachment settings that is say based on (Choice control = "Yes") = minimum attachments = 1 if "No" minimum attachments = 0


6 replies

Userlevel 7
Badge +11

Hi Warwick,

 

you're right.  With the new validation for Attachment controls, you can't base it on other controls or a condition.  I'll le the appropriate team know and maybe that can be something added in the future.

 

Your JS is awesome.  I tweaked it a little for a form I needed to use recently, which was also based on a Checkbox and if it was checked, there needed to be a minimum of 1 attachment on the form.

 

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;

          }

      }

}

cheers,

Vadim

Userlevel 7
Badge +11

Hi Muhammad,

instead of the code, have your tried the built in validation settings?

Attachment Validation in Nintex Forms

cheers,

Vadim

Badge

Hi Vadim,

I have a form with multiple attachment controls as follows:

Attachment Control 1 (default): Customer Files

Attachment Control 2: Business Justifications

Attachment Control 3: Old Versions

I have tried your JS and it only applies to the default attachment control, how do I make changes to the script to handle Attachment Control 2 and 3?

Thanks,

Woon Woon, Gan

Badge +2

Hi Vadim,

I have the same scenario where i want the attachment to be mandatory if a check box is 'checked'. My check box name is Acknowledgementstatement

Where would i add the name of my check box into the javascript?

Any help would be appreciated.

Thanks

Badge +6

Try using the following:

function FormatValidationError(control) {

    control.addClass('validationError');

}

function ClearValidationError(control) {

    control.removeClass('validationError');

}

And this CSS class:

.validationError {

    border: 2px solid red !important;

}

Userlevel 2
Badge +11

Hi Muhammed,

 

Could you elaborate on your comment by providing the code that worked?

Reply