Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#824808
Hello,

I have a dynaform with a file object and a checkbox object. The file object should be disabled and so it's validation when the user checks the checkbox the file object is now enabled and its validation as well. All of this works visually, it turns from gray to white, but you can't actually upload anything. If you click the file upload object no window appears for you to select a file.

The file object is disabled and its validation enabled in its properties. If I enable it in the properties it works and I can upload documents, but the objects start enabled when it shouldn't. This also happens if I use getControl().prop('disable', true);

Is this a bug? is there any other way to do this

This is the code I'm using:
Code: Select all
function enableFile()
{
  var attachment = $("#attachment").getValue();
  if(attachment == true)
  {
    $("#Gridfile").getControl().attr('disabled',false);
    $("#Gridfile").enableValidation();
  }
  else if (attachment == false)
  {
    $("#Gridfile").getControl().attr('disabled',true);
    $("#Gridfile").disableValidation();
    $("#Gridfile").clear();
  }
}
Last edited by fcomijangos on Wed Jun 12, 2019 5:05 pm, edited 1 time in total.
#826430
Code: Select all
var gridId            = 'productsList';       //set to ID of grid
var gridCheckboxId    = 'inProduction';       //set to ID of checkbox in grid
var gridCheckboxColNo = 2;                    //set to column number of checkbox in grid
var gridFileId        = 'productionSchedule'; //set to ID of File field in grid
var gridFileColNo     = 3;                    //set to column number of File field in grid

var reGridCheckboxChanged = new RegExp("^\\["+gridId+"\\]\\[(\\d+)\\]\\["+gridCheckboxId+"\\]$");
var formId = $("form").prop("id");

//execute when any field in Dynaform is changed:
$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
  var aMatch = fieldId.match(reGridCheckboxChanged);
  
  //if the value of the "In Production?" checkbox changed in the grid:
  if (aMatch) {
    var rowNo = parseInt( aMatch[1] );    
    enableOrDisableGridFile(rowNo, newVal);
  }
});

//Function to enable the File field in grid if the checkboxVal is marked.
//If the checkbox is not marked, then the File field will be disabled and 
//any selected file will be deleted. 
function enableOrDisableGridFile(rowNo, checkboxVal) {
  //subtract 1 from the row and column numbers because start counting from 0, not 1.
  var oFileGridTable = getFieldById(gridId).gridtable[ rowNo - 1 ][ gridFileColNo - 1 ];
  var oFileButton = $("[id='["+gridId+"]["+rowNo+"]["+gridFileId+"]']").find("button");
  
  if (checkboxVal == "0" || checkboxVal == '"0"') { //if the checkbox isn't marked:
    oFileGridTable.disableValidation(); //only need this if the File field is required
    
    var buttonLabel = "Allowed file extensions: " + oFileGridTable.getInfo().extensions;
    oFileButton.text(buttonLabel); //remove filename from File's button
    
    oFileButton.attr("disabled", true); //disable the File's button
      
    $("[id='form["+gridId+"]["+rowNo+"]["+gridFileId+"]']").val('');       //clear hidden file input field
    $("[id='form["+gridId+"]["+rowNo+"]["+gridFileId+"_label]']").val(''); //clear filename in hidden text field
  }
  else { //if the checkbox is marked:
    oFileGridTable.enableValidation();   //only need this if the File field is required
    oFileButton.attr("disabled", false); //enable the File's button
  }
}

//Loop through existing grid rows to enable/disable File fields when Dynaform loads:
var oGrid = $("#"+gridId);
var nRows = oGrid.getNumberRows();

for (var i = 1; i <= nRows; i++) {
  enableOrDisableGridFile( i, oGrid.getValue(i, gridCheckboxColNo) );
}

//enable/disable the File field in new rows added to the grid:
oGrid.onAddRow( function(aNewRow, oNewGrid, rowNumber) {
  enableOrDisableGridFile( rowNumber, oNewGrid.getValue(rowNumber, gridCheckboxColNo) );
});
#826443
Amy,
Did you directly import my example? If you are trying to use this code in an existing Dynaform, then you will have to change the variables at the top of the code to match your Dynaform.

This works in my installation:
PM 3.3.10 Community (manual install) in Debian 9.5 with Firefox 60.5

What is your environment?

If you press F12 to turn on your web browser's debugger, do you see any errors under the "Console" tab when using the Dynaform?
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]