Minimum attachment validation not working

  • 8 January 2016
  • 6 replies
  • 29 views

Badge +11

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


6 replies

Badge +7

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 :

164614_pastedImage_0.png

Hope this helps happy.png

Badge +11

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?

Badge +7

Hi Philipp,

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

Could you please give us the filename you tried?

Badge +11

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.

Badge +7

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 :

164895_pastedImage_1.png

Badge +11

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

Reply