This is not so much a question as an answer to my own issue. We are starting to convert some older forms to the modern designer and I have a couple that need to count the number of uploaded files. One case is the submit button is enabled if they have at least one file uploaded, otherwise they can only click the "Return for Correction" button.
Here it the code I came up with:
/*--------------------------------------------------------------------------------*/ /* Start: counting uploaded files */ /*--------------------------------------------------------------------------------*/ function countUploadedFiles(theUploadFieldID) { let theFieldObject; let theFieldCount = 0; /* get the field object with the ID */ theFieldObject = LFForm.findFieldsByFieldId(theUploadFieldID) /* loop through all field objects with the ID */ /* in the case of an upload there will be only one */ theFieldObject.forEach(function (currField) { /* grab the data's length. */ //console.table (currField); theFieldCount = currField.data.length; }); return theFieldCount; }; /* END: function countUploadedFiles(theFieldIDNumber) */ const uploadFieldID = 50; const fileCountFieldID = 51; /* When file upload changes */ LFForm.onFieldChange(function(){ //console.log("Upload Changed " ); let fileCount; fileCount = countUploadedFiles(uploadFieldID); LFForm.setFieldValues({fieldId: fileCountFieldID}, fileCount); //console.log("fileCount: " + fileCount); }, {fieldId: uploadFieldID}); /*--------------------------------------------------------------------------------*/ /* END: counting uploaded files */ /*--------------------------------------------------------------------------------*/
I am open to any improvements :)