Undocumented JavaScript functions

From pmusers
Jump to: navigation, search

There are a number of undocumented JavaScript methods that can called in BPMN Dynaforms found in ProcessMaker version 3.0 and later.

form.isValid()

The form.isValid() function defined in workflow/public_html/lib/pmdynaform/build/js/PMDynaform.js:5962 can be called to validate all the fields in the Dynaform. It shows red error messages under blank fields whose required property is enabled and under fields whose value does not match their validate regular expression.

getFormById("form-id").isValid()

Return value:

It returns true if all fields in the Dynaform are good and false if any fields whose values aren't validated.

Example:

The following JavaScript code first checks that all the fields are valid, before calling the form.saveForm() method.

var formId = $("form").prop("id");
if (getFormById(formId)isValid == true) {
   $("#"+formId).saveForm();
}

field.validate()

The field.validate() function validates the value in a specified field. It shows the red error message for an empty required field or a text field which doesn't match its validate regular expression. Otherwise is shows nothing in the Dynaform.

getFieldById("field-id").validate()

Return value:

The function returns the field's model object, regardless of whether the field's value if validated or not.

Example:

When the value of the "howContact" dropdown changes to "home_visit", validate the "address" field to make sure that it isn't left empty.

$("#howContact").setOnchange( function(newVal, oldVal) {
   if (newVal == "home_visit") {
      getFieldById("address").validate();
   }
}

field.showRequired() and field.hideRequired()

The field.showRequired() method shows the red asterisk (*) next to a specified field's label to show that it is required. then use the following methods:

getFieldById("field-id").showRequired()


The field.hideRequired() hides the red asterisk (*) for required fields:

getFieldById("field-id").hideRequired()


These methods can only be used on fields that are marked as required or have a defined validate property. Unless there is a compelling reason to hide the asterisk without effecting the validation, it is recommended to use the enableValidation() and disableValidation() instead of these methods.

form.items.asArray()

form.items.asArray() returns an array of all the fields in a Dynaform.

getFormById("form-id").items.asArray()

Example:

var aFields = getFormById( $("form").prop("id") ).items.asArray();
for (var i = 0; i < aFields.length; i++) {
   aFields[i].validate();
}

parent.Actions.menu-function()

The following functions can be used in a Dynaform's JavaScript code to execute options from the Information menu:

  • parent.Actions.showHistoryMessages(): Shows the emails sent by the current case, like the Information > Messages History menu.
  • parent.Actions.processMap(): Shows the process map from the current case, like the Information > Process Map menu.
  • parent.Actions.processInformation(): Shows information about the current process, like the Information > Process Information menu.
  • parent.Actions.taskInformation(): Shows information about the current task, like the Information > Task Information menu.
  • parent.Actions.caseHistory(): Shows a list of the tasks and their assigned users which have been opened or completed from the current case, like the Information > Case History menu.
  • parent.Actions.dynaformHistory(): Shows the list of Dynaforms from the current task in the current case, like the Information > Dynaforms menu.
  • parent.Actions.changeLogHistory(): Shows the variables which have been changed in each Dynaform in the current case and the user who committed the changes, like the Information > Change Log menu.
  • parent.Actions.uploadedDocuments(): Shows a list of files that have been uploaded to the current case in File and MultipleFile fields and Input Documents, like the Information > Uploaded Documents menu.
  • parent.Actions.generatedDocuments(): Shows a list of the Output Document files generated in the current case, like the Information > Generated Documents menu.


The following functions can be used in a Dynaform's JavaScript code to execute options from the Action menu:

  • parent.Actions.getUsersToReassign(): Shows a dialog to reassign the current case to another user, like the Action > Reassign menu.
  • parent.Actions.setUnpauseCaseDate(): Shows a dialog to pause the current case, like the Action > Pause menu.
  • parent.Actions.cancelCase(): Shows a dialog to reassign the current case to another user, like the Action > Reassign menu.


These functions are defined in the file workflow/engine/templates/cases/open.js, which can be modified to prevent users from executing any of these functions.


Example:

Create a button with the ID "myCancelButton", then add the following JavaScript to the Dynaform:

$("#myCancelButton").find("button").click( function() {
    parent.Actions.cancelCase();
})