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
Solved! Go to Solution.
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
Dear Vadim,
Thanks a lot for your efforts. but i have one question how to prevent this button from submitting?
cuz after using your code it's still submitting the form even if "arguments.IsValid = false;"
Thanks in advance
Hi Muhammad,
instead of the code, have your tried the built in validation settings?
Attachment Validation in Nintex Forms
cheers,
Vadim
Hi Vadim,
Thanks for your quick response, Yes i tried the built in validation but it's not working.
when i set the minimum attachments to 1 and try to submit the form without attaching any documents, The form is submitted.
i tried to use return false; after arguments.IsValid = false; but nothing happens also.
Thanks,
Muhammad
Hi Vadim,
I solved the issue the problem was in arguments.IsValid. i removed it and every thing worked fine.
Thanks,
Muhammad
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
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
In control settings, save clientID to a JS variable. And modify here (var Control = NWF$("#" + varMyCheckBoxID); ) to your variable name.
Thanks for the script. It works. It does stop from submitting when failing validation. However, it doesn't highlight the checkbox where I enable custom validation. I put Control.css("border", "2px red solid"); before/after " arguments.IsValid = false;" but still no effect.
Any suggestion?
Thanks,