Unofficial documentation how to do interesting things and work around problems in ProcessMaker

Moderator: amosbatto

Forum rules: Unofficial documentation for features which have not been tested by Quality Assurance or may change in future versions of ProcessMaker
By amosbatto
#789380
The control.mergeOptions() method is used to set the list of additional options in a dropdown box, suggest box, checkgroup or radiogroup. Calling this method will replace any options normally set by the SQL query or pulled from a variable and the new options will be added after the fixed options which are set in the options property of the control. Note that this method is only available in the Backbone object for a control, but not in its jQuery object.
Code: Select all
getFieldById("control-id").mergeOptions(remoteOptions, returnOptions)
Parameters:
- remoteOptions: An array of option objects in the following format:
Code: Select all
[ 
  { value: "value1",  label: "label1"},
  { value: "value2",  label: "label2"},
  ...
]
Where the value is what is stored when the option is selected and the label is what is display to the user. Note that label can also be named text.
- returnOptions: If set to true, then the complete set of options for the control is returned, including the fixed list of options set in the control's options property.

Return Value:
The current list of variable options for the control are returned in an array of options objects:
Code: Select all
[ 
  { value: "value1",  label: "label1"},
  { value: "value2",  label: "label2"},
  ...
]
Example 1:
The options "Telephone" and "Fax" are added to the list of fixed options in the "howContact" dropdown box:
Code: Select all
getFieldById("howContact").mergeOptions( [
   {value: "phone", label: "Telephone"}, 
   {value: "fax", label: "Fax"}
] );
Example 2:
Add a new option to a checkgroup with the ID "selectClient", when the user fills out the "clientName" field and clicks on the "addClient" button. Once the new client is added to the list, it will be deleted from the "clientName" field, so another name can be entered.
Code: Select all
$("#addClient").click(function() {
   var client = $("#clientName").getValue();
   if (client == "") {
      alert("Please enter new client name before adding it to the list of clients.");
   }
   else {
      getFieldById("selectClient").mergeOptions( [{"value": client, "label": client}] ); 
      $("#clientName").setValue(""); //reset for another client name to be added
   }
] );
Note: The following code can be used if needing to clear the complete list of options in a dropdown box, suggest box, checkgroup or radiogroup, including the fixed options set with the control's options property:
Code: Select all
var fld = getFieldById("control-id");
fld.model.attributes.remoteOptions = [];
fld.model.attributes.optionsSql = [];
fld.model.attributes.options = [];
fld._setOptions([]);

The ID in your @@supervisorId variable is probably[…]

What version of PM are you using? You should use a[…]

First of all, do you know PHP and JavaScript? If […]

Force Skin

When you set the User Experience to "Switchab[…]