We have a file upload button and are trying to count the files uploaded and store them in a field that will determine other required fields based on whether files are uploaded or not. We can get the count of the files uploaded we just can't trigger it in a way that seems efficient. The current code that works:
//On draft upload. We update the file count and need a more efficient yet reliable trigger. var draftDocCount=0; $('#q29').bind('DOMSubtreeModified', function (e) { if (e.target.innerHTML.length>0){ draftDocCount=$('#q29 .file-del').length; //get file count } $('#q205 input').val(draftDocCount);//store file count in another field });
This code works but triggers anywhere from 13-16 times for each upload. This seems to slow down the upload speed. Is there a better trigger?
The classic triggers ie. change and blur trigger before the attachment is uploaded resulting in a number that doesn't include the currently uploading attachment.
The solution must also trigger on a file delete to update the total files.