cancel
Showing results for 
Search instead for 
Did you mean: 
Automation Master
Automation Master

Minimum attachment validation not working

Jump to solution

Hi,

i have following scenario: On my Nintex Form (2013) i have set a minimum of 1 attachment by directly editing the control settings. Additionally I have some JS code, that checks for special characters and for the length of the filename.

I put the JS code directly in the Form settings "Custom JavaScript" area. This is the JS:

function ValidateAttachments() {

var isValid = true;

var maxFileNameLength = 100;

NWF$('.nf-attachmentsTable').find('tbody').find('tr').each(function() {

  var file = NWF$(this);

  var fileName = file.find('span')[0].innerText;

 

  var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);

  if (match) {

   isValid = false;

   alert('invalid file name: ' + fileName + '; no special characters allowed');

  } else if (fileName.length > maxFileNameLength){

    isValid = false;

    alert('too long file name: ' + fileName + '; only 100 characters allowed ');

  }

});

return isValid;

}

The function is called when the save button is clicked. I added the function as Client Click event in the "Advanced" tab of the control settings of the save button ("return ValidateAttachments()")

Funny thing is, both checks are working fine for themselves. But after I implement the JS method, the standard validation of the attachment control, checking for the minimum number of 1 attachment, won't work anymore. Which means as soon as i implement the JS method and let it execute by clicking the save button, I can check for special characters and the length of the filename but i can also just save the form without addind any attachment at all, although the control validation still says minimum of 1 attachment.

Can someone explain me why this is happening and what i need to do to get both checks applied? Of course i could try to add the "minimum numer of attachments"-check in the JS code as well, but I need to understand why my code is deactivating the standard validation.

Hopefully someone can enlighten me.

Thanks in advance

Philipp

0 Kudos
Reply
7 Replies
pfudala
Nintex Newbie

Re: Minimum attachment validation not working

Jump to solution

Hi Philipp,

I tested your issue and it seems that your "Client click" syntax is wrong.

To perform both validations, you have to set the parameter without "return", as below :

Hope this helps

Reply
Not applicable

Re: Minimum attachment validation not working

Jump to solution

Hi, Philipp Lucas​, Keep us posted on your progress. Thanks!

0 Kudos
Reply
Automation Master
Automation Master

Re: Minimum attachment validation not working

Jump to solution

Hi Pierre,

thank you very much for the hint. Without the "return" the file name is checked, but the form is still submitted if I try to upload a file with a name that contains special chars.

So when the form is saved, the user receives the typical "invalid file name" exception, and the file is not attached to the item but the item is created anyway. I would rather like the item not to get created before there are only files with valid file names attached and keep my user from seeing the exception.

Any suggestion?

0 Kudos
Reply
pfudala
Nintex Newbie

Re: Minimum attachment validation not working

Jump to solution

Hi Philipp,

I tested a filename with the '~' character and it worked.

Could you please give us the filename you tried?

0 Kudos
Reply
Automation Master
Automation Master

Re: Minimum attachment validation not working

Jump to solution

Hey Pierre,

i tried e. g. "testdoc&#.docx" and now also "testdoc~.docx". The function is working though! I get an alert informing me about the special characters in the filename. However, the form still gets submitted, the exception is shown and the item is created without attachment.

But I do NOT want the form to be submitted as long as there are any invalid files attached.

0 Kudos
Reply
Highlighted
pfudala
Nintex Newbie

Re: Minimum attachment validation not working

Jump to solution

You're right. I didn't test it without filling another mandatory field...

You could achieve this with another way : Validation rules.

Select the attachment control and add a rule.

Set it as below :

View solution in original post

Reply
Automation Master
Automation Master

Re: Minimum attachment validation not working

Jump to solution

That seems to do the trick, thank you very much! Didn't know you could call your JS-functions in these validation rules.

Best regards

Philipp

0 Kudos
Reply