Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By justinopsky
#828743
I need to check in javascript if a file is valid, that is, if its size is not zero before its submission.
I'm using a file upload, not multiple file upload.

Can anyone help me?
Thanks
#828759
Hi,
You can use code like this:
Code: Select all
getFormById(dyn_uid1).setOnSubmit(function() {
	var file_size = $('#form\\[fileVar001\\]')[0].files[0].size;
	if(file_size < (1000*1024) || file_size > (5000*1024)){
		alert('Set file!');
		return false;
	}
});
http://pmlearning.info
Thanks
#828765
Thanks programerboy
Using your code
I change it for use also in a grid
Code: Select all
var formId = $("form").prop("id");
getFormById(formId).setOnSubmit( function() {
  
  var file_size = $('#form\\[fileVar001\\]')[0].files[0].size;
  if(file_size < (1000*1024) || file_size > (5000*1024)){
    alert('Set file!');
    return false;
  }
    
  var gridId     = 'gridDocumentos';    //set to the ID of the grid
  var fileAnexo = 'fileAnexo';
  var aGridValues = $("#gridDocumentos").getValue();
 
  for (var i = 0; i < aGridValues.length; i++) {
      var file_size = $("#form\\["+gridId+"\\]\\["+(i+1)+"\\]\\["+fileAnexo+"\\]")[0].files[0].size;
      if(file_size < (1000*1024) || file_size > (5000*1024)){
        alert('Set grid file!');
        return false;
      }
  }
});

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]