PAK Commands – Create Form
1. Summary
This command lets you create a multi form page which the user has to fill out to continue.
2. Examples
Due to simplicity, the descriptiveText input parameter will be left empty for the examples. By default, it is set to „Please fill out the form below to continue“.
| All example images use the Human Task representation of the Workflow Executor. |
The labelList input parameter is required and represents each input which will be a text field by default.
2.1. Minimal Command Execution
|
|
|
In the first example we ran the command with the labelList "First Name, Last Name, Email". By default, all inputs will be text field and every input is mandatory. When the user for example fills the form with John, Doe and john@doe.com, the formObject will be written as {"First Name":"John","Last Name":"Doe","Email":"john@doe.com"}.
2.2. Adding Optional Fields
Sometimes not all fields have to be required, to exclude certain fields we can make use of the mandatoryFields parameter, which accepts a list of boolean values.
|
|
|
In this example, we made the Email-field optional, this can be done by providing mandatoryFields with "true, true, false", indicating that the first two inputs shall be mandatory, the last one however will be optional. The result can now either be the same as above, or {"First Name":"John","Last Name":"Doe","Email":null}.
2.3. Adding Different Input Types
Only having text inputs will not fit our long-term needs, if we want to include some kind of date, for example the date of expiry, we can use the dataTypes parameter. All available types are text, number, boolean, date, textarea, input and select (see the table below for more information).
|
|
|
In the third example, we substituted Email with Date of Expiry in the label list. To make the input a date chooser we can set dataTypes to "Text, Text, Date". The result will now be written as {"First Name":"John","Last Name":"Doe","Date of Expiry":"2000-06-06T00:00:00.000Z"}.
Available data types are:
| DataType | Description |
|---|---|
|
|
A normal, one line, text input field. |
|
|
An input field, that only allows numbers (positive and negative) as values. Supplies a button to increase/decrease a number by one. |
|
|
A checkbox input. |
|
|
A field to enter a date by typing or selecting a day out of a calendar view. |
|
|
A text input with multiple lines and adjustable height. |
|
|
A drop down menu, where one of the specified options can be selected. |
|
|
A drop down menu, where one of the specified options can be selected, with the possibility of inserting custom data. |
2.4. Setting initial Values
In the parameter initialValues a list of default values can be added to prefill the form. For the example above this parameter could be filled with "John,Doe,2000-06-06T00:00:00.000Z" to produce following prefilled table.
In the previous examples, the user typed "John", "Doe" and the chose date. Now the values are already set, but the user can change them again, if needed.
|
|
|
2.5. Customizing the JSON Output
The last parameter we can make use of is the fieldIds variable, which lets us choose the name of the inputs in the resulting JSON object. For instance, we might want to stay conformed to the Java variable naming syntax, so we can transform our JSON to a Java object. When we for example set fieldIds to firstName, lastName, dateOfExpiry, the resulting JSON object will be {"firstName":"John","lastName":"Doe","dateOfExpiry":"2000-06-06T00:00:00.000Z"}.
2.6. A complete Example
We will create a form to ask for a Tea-Time Meeting. We want to know who is coming and how many friends they will bring with them, if they will bring a desert and when they plan on attending. A short introduction and their drink of choice are also required.
We enter the label descriptions into labelList, so the user knows what the input is about. The dataTypes are set to the corresponding inputs and the options we want the „select“ to have are already supplied.
After setting the descriptiveText to our message, we provide the fieldIds to declare the JSON-Keys, under which the values will be saved. We enter initialValues, providing a default-value for certain inputs. Finally, we set the boolean in mandatoryFields to true, where an answer is required.
|
|
|
The saved result would then be saved as:
{
"name":"John Doe",
"guests" : 2,
"desert" : true,
"date":"2024-12-06T00:00:00.000Z",
"introduction":"Hi, I'm John! I love talking about food and i love baking (especially Apple-Crumble-Pie ;)",
"drink":"coffee"
}