Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By cosyxu
#815984
G'day Amo,

Thanks for your help last time.

I was wondering if there any way that I can clear the session or variables every time when I open the Dyanform?

I'm using PM 3.2.2 which allows me to have multiple steps for the web-entry form. Now I have three forms, but I found as long as I submit for first and second forms and I didn't submit the last one and then I close the Dynaform, all the variables will be stored when I open it next time.

So is there any way that I can clear all the variables or session every time when I close the Dynaform or clear the variable s when I open the Dyanform?

Any ideas? Thanks.
Yuan
User avatar
By amosbatto
#816000
You can add some JavaScript to reset all the fields when the Dynaform loads:
Code: Select all
var formId = $("form").prop("id");
getFormById(formId).el.reset()
I'm not sure whether the old values will still be inserted when the Dynaform is reset. If resetting doesn't work, then you will have to clear all the fields in the form, like this:
Code: Select all
$("#field1").setValue("");
$("#field2").setValue("");
User avatar
By amosbatto
#816001
I found another way to clear all the fields in a form:
Code: Select all
function clearAllFields() {
  var aClearableTypes = ['text', 'textarea', 'dropdown', 'suggest', 'radio', 'hidden'];
  var formId = $("form").prop("id");
  var aRows = getFormById(formId).model.attributes.items
  
  for (i in aRows) {   
    for (ii in aRows[i]) {
      var oField = aRows[i][ii];
      
      if (aClearableTypes.indexOf( oField.type ) != -1) {
        $( "#" + oField.id ).setValue( oField.defaultValue );
      }
      else if (oField.type == 'checkbox') {
        if (oField.defaultValue == '')
          $( "#" + oField.id ).setValue( "0" );
        else
          $( "#" + oField.id ).setValue( oField.defaultValue );
      }
      else if (oField.type == 'checkgroup') {
        if (oField.defaultValue == '')
          $( "#" + oField.id ).setValue( [] );
        else
          $( "#" + oField.id ).setValue( oField.defaultValue );
      }
      else if (oField.type == 'grid') {
        var oGrid = $( "#" + oField.id );
        var iRow = oGrid.getNumberRows();
        
        for (; iRow > 0; iRow--) {
          oGrid.deleteRow(iRow);
        }
        
        if (oGrid.getNumberRows() == 0) {
          oGrid.addRow();
        }
      }
      else if (oField.type == 'datetime') {
        $( "#" + oField.id ).setValue( oField.defaultDate );
      }
      else if (oField.type == 'multipleFile') {
        $( "#" + oField.id ).find("a.fa-trash").click();
      }
    }
  }
}

function resetClickHandler() {
  clearAllFields();
  //reset click handler because ProcessMaker clears it after every click:
  $("#resetBtn").find("button").click(resetClickHandler);
}

$("#resetBtn").find("button").click(resetClickHandler);
(13.95 KiB) Downloaded 279 times

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

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]