I have need for very custom validation on an attachment field.
We have a series of cascading drop down menus that make the attachment field visible based on the selections. When the conditions that make the attachments visible I want to require an attachment. When the attachments are not visible, I don't want attachments to be required.
Anyone have a good way to go about setting this up? I don't see any way to do this with any of the out of the box functions and validation doesn't seem to work with rules either. I put a real simple condition like "IsEmptyOrNull" in the conditional validation field, and if I open the form initially then click save that validation kicks off, invalidates the form and puts my custom error message up, but the moment I select one of the cascading drop down options, the form "refreshes" and when I try to save the form, the attachment validation passes (even though I have not attached anything).
Solved! Go to Solution.
return NWF.FormFiller.Attachments.GetAttachedFilesCount(NWF.FormFiller.Functions.GetFillerDivObjectForControl(NWF$("#"+NWF$("." + attCtrlClassName + " .nf-attachmentsRow").id)).data('controlid'))
then I simply use it in validation rules like
GetNumberOfAttachments("AttachmentControlClass") < 1
that allows me to combine it with other needed logic
While this is nice, no where in my question did I ask for validation for the number of attachments. Where exactly are you going with this? I think this may be something you should put in a separate article or something as this is unrelated to my question.
you asked for:
When the conditions that make the attachments visible I want to require an attachment. When the attachments are not visible, I don't want attachments to be required.
number of attachments less than 1 means there is no attachment.
if you AND that with condition that makes your attachment control visible and place that combined condition into validation rule, once the control is visible and no attachment is included your form will not validate.
is it clear now?