Thanks for your reply, I had read this discussion before. However, when I put code to my Nintex 2016, the form cannot be opened and stuck in the loading icon.
Can anyone suggest another way to deal with it? Thanks
I guess you mean Mark Altman's script..
I've tried that script and noticed there is missing one closing brace there.
as well check for case when there is not any file attached needed little extend.
finally I reverted what value is returned in what case so that it is easier to use in validation rules
try following version
function IsFileSizeExceeded(maxSizeInMB) {
var isValid=false;
for ( var i=0; i<NWF$('input"type=file]').length; i++ ) {
if(NWF$('inputntype=file]')ci].files.length>0 && NWF$('inputntype=file]')ci].filesc0]!==null && NWF$('inputntype=file]')ci].filesc0]!==undefined) {
if(NWF$('input type=file]')ni].filesn0].size>(maxSizeInMB*1048600)) {
var sizeInMB = Math.round(NWF$('input"type=file]')ni].files/0].size / 10486) / 100;
isValid=true;
alert("The maximum file size is "+maxSizeInMB+"MB, but the file " + NWF$('input)>i].filesn0].name + " is " + sizeInMB + "MB. Please reduce the file size before uploading.");
break;
}
}
}
return isValid;
}
I used it as follows
Thanks @marian hatala. You save me.
This script is for 1mb, where or how change a 15mb for example???
Thanks
Federico MS.
max allowed size is determined by input paramter of IsFileSizeExceeded() function.
This works great. but it seems that it validate the size of each uploaded file.
in my case I need to know the total of all uploaded files in one attachment control. the reason is to attach them in emails.
any help?. I'm no good with JS.
kindly, vote for this update: Validate the max size of attachment control – Customer Feedback for Nintex
Hi Emha,
This code is blocking the saving of an attachment in IE. How to over come from this?
Regards,
Hema
the code is one and half year old. a lot changed in the forms functionality and and its internal structures since then.
so it's of no surprise it doesn't work anymore ...
try following, this worked for me on forms v2.11.5.0
function IsFileSizeExceeded(maxSizeInMB) {
var isValid = false;
for (var i = 0; i < NWF$('input[type=file].nf-attachmentFileInput').length; i++) {
if (NWF$('input[type=file].nf-attachmentFileInput')[i].files.length > 0 && NWF$('input[type=file].nf-attachmentFileInput')[i].files[0] !== null && NWF$('input[type=file].nf-attachmentFileInput')[i].files[0] !== undefined) {
if (NWF$('input[type=file].nf-attachmentFileInput')[i].files[0].size > (maxSizeInMB * 1048600)) {
var sizeInMB = Math.round(NWF$('input[type=file].nf-attachmentFileInput')[i].files[0].size / 10486) / 100; // # MB with two decimal places
isValid = true;
alert("The maximum file size is " + maxSizeInMB + "MB, but the file " + NWF$('input[type=file].nf-attachmentFileInput')[i].files[0].name + " is " + sizeInMB + "MB. Please reduce the file size before uploading.");
break;
}
}
}
return isValid;
}
I used the code and it seems to work fine with one caveat. It attaches one less attachment after the form is valid. Basically, it does not attach the last attachment even if that attachment is valid.
Anyone else ran into this issue?
Is there any other approach I can use to validate the attachment size?
I cannot reproduce the issue. for me all the attachments are saved.
have you tried original code or one recently updated?
have you customized the code anyhow?
do you test it with a different form version?
Thank you for your reply. I really appreciate it.
My forms version is Version: 2.6.0.0. I have used the previous code, the one you posted on page #1. Code works like a charm. The only challenge is as soon I use that code I miss one attachment.
I did make some changes to the code but I also tried using your code as is but it was the same result.
Here is the modified code that I used.
function IsFileSizeExceeded(maxSizeInMB) {
var isValid=false;
var totalSize=0;
for ( var i=0; i<NWF$('input[type=file]').length; i++ ) {
if(NWF$('input[type=file]')[i].files.length>0 && NWF$('input[type=file]')[i].files[0]!==null && NWF$('input[type=file]')[i].files[0]!==undefined) {
totalSize = totalSize + Number(NWF$('input[type=file]')[i].files[0].size);
}
}
if(totalSize > (maxSizeInMB*1048600)) {
isValid=true;
}
return isValid;
}
If the code works for you then it could be my version of Nintex Forms. In that case, anything else you can suggest?
have you tried with newer code?
Even I am facing the same issue..it seems to be browser specific. The code works perfectly in Chrome but the last attachment gets removed when tried in IE.
I agree.
This code works completely fine and attachments show up properly when using the Chrome but do not work with Edge and IE.
I used the code above but that code does not work at all but likely because my Forms version is older.
Is there any other way instead of using the validation?
I'm not sure what might be different in that old version...
have you checked developer console whether there are not reported any errors? are you able to debug the code?
I'm affraid I cannot help further.
@emha Cheers buddy. You were very helpful so far. Appreciate all the inputs.
@Vaish If you find any workaround please share. I am going to try a pure jQuery route and see if it helps.
It seems that I must have done something wrong with the new script provided by @emha
Just updated the new script and this time it worked as expected. Sharing my modified script in case if anyone wants to use it. This script checks all attachments size as oppose to each attachment.
function IsFileSizeExceeded(maxSizeInMB) {
var isValid = false;
var totalSize = 0;
for (var i = 0; i < NWF$('input[type=file].nf-attachmentFileInput').length; i++) {
if (NWF$('input[type=file].nf-attachmentFileInput')[i].files.length > 0 && NWF$('input[type=file].nf-attachmentFileInput')[i].files[0] !== null && NWF$('input[type=file].nf-attachmentFileInput')[i].files[0] !== undefined) {
totalSize = totalSize + Number(NWF$('input[type=file].nf-attachmentFileInput')[i].files[0].size);
}
}
if (totalSize > (maxSizeInMB * 1048600)) {
isValid = true;
}
Thank you very much @emha
This works on all three browsers i.e. Edge, Chrome and IE.
great!
just for reference, do you say this works on 2.6.0?
Yes. Works on 2.6.0
This script was working great. but after updating nintex forms i noticed that it's not working properly.
the form is not uploading any files. it shows blank.
after I removed the script, it worked fine.
does anyone faced the same issue? or have the updated script?
And now the validation is not working properly in the lookup fields.
After i added that code then which is restricting more than 1 MB file after that i cannot upload any file from attachment controls? can you tell me any workaround?