Plug-In Forms (also called “Action Forms”)

Omni Automation enables the creation of powerful automation tools for addressing the tasks and challenges involved in the creative use of productivity applications like Omni Productivity Suite.

Plug-In Forms (also referred to as Action Forms) enable plug-ins to display standard form selection and input elements, such as text fields, menus, and checkboxes (switches on iOS), so the user may provide the plug-in with the choices and data to be used by the plug-in during the execution of its processing code.

In addition, Form Elements may include optional labels and be assigned default values and ordering, so as to create Form Dialogs that present data and choices in an easy-to-understand and organized manner. And Form Dialogs can be enhanced with customized prompts and approval button titles.

(⬇ see below ) A macOS form dialog sheet

form-example-with-callouts

The following documentation details the use of the Form and Form.Field classes, along with their corresponding functions and methods, demonstrating how to create, display, and respond to forms included in your plug-ins.

This overview will begin with an examination of the Form class and how to create a new form object in a script.

The Form Class

The Form class provides a mechanism to collect input from the user. Each form contains one or more instances of the Form.Field subclasses (form elements), to which each are assigned a unique key. As the form is filled out by the user, the form’s default values object is populated with the values of the form elements in the form dialog.

Instances of the Form class are created using the standard JavaScript new object constructor:

Form Instance


var inputForm = new Form()

The result is an empty instance of the Form class, ready to contain various elements of the Form.Field class, such as text input fields, date pickers, checkboxes, and popup menus.

Instance Properties

Instance Functions

Form Elements

An instance of the Form class is a container that contains various form elements, such as popup menus, checkboxes, and date and text input fields. All of the form elements are instances of the Form.Field class, and they share the following properties:

Instances of the Form.Field class are created using the standard JavaScript new object constructor including the parameters specific to each type of element:

For example, here is script code that creates each of the various types of form elements:

Form Elements


// TEXT INPUT FIELD textInput = new Form.Field.String( "textInput", "Name", null ) // DATE INPUT FIELD dateInput = new Form.Field.Date( "dateInput", "Date", null ) // OPTIONS MENU optionsMenu = new Form.Field.Option( "optionsMenu", "Position", [1,2,3], ["Top", "Middle", "Bottom"], 1 ) // SOLITARY CHECKBOX|SWITCH solitaryCheckbox = new Form.Field.Checkbox( "checkboxSwitch", "Append to selected paragraph", false ) // MULTIPLE OPTIONS multiOptionMenu = new Form.Field.MultipleOptions( "multipleOptions", "Multiple Options", [0,1,3], ["One","Two","Three"], [] )

Adding Elements to a Form

Created Form Elements are added to an existing Form instance using the addField(…) instance function of the Form class.

For example, here is how the previously created form elements would be added to the previously created form:

Add Elements to Form


inputForm = new Form() inputForm.addField(textInput) inputForm.addField(dateInput) inputForm.addField(optionsMenu) inputForm.addField(solitaryCheckbox) inputForm.addField(multiOptionMenu)

NOTE: if a position index is not included as a parameter in the addField(…) function, the created element is added to the end of the set of current form elements. Also, if the position index parameter is not used, then form elements are added to the current set of form elements in the order in which the function is called to add them. The topmost position index is 0.

Displaying the Form

Once a form has been populated with elements, it is displayed within the application by using the show(…) instance function of the Form class:

The show(…) function takes two text string for its parameters: the dialog title/prompt, and optionally, the title of the approval button.

NOTE: The JavaScript Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. It is discussed in more detail in the next section about validating, retrieving, and using the form data.

Here is an example script that will display a form containing each of the form element types:

NOTE: This page contains interactive script examples that are executed only with your approval. See the section on Script Security for details about allowing the execution of remote scripts.
inputForm = new Form() textInput = new Form.Field.String("textInput", "Name", null) dateInput = new Form.Field.Date("dateInput", "Date", null) optionsMenu = new Form.Field.Option( "menu", "Position", [1,2,3], ["Top", "Middle", "Bottom"], 1 ) solitaryCheckbox = new Form.Field.Checkbox( "checkbox", "Append to selected paragraph", false ) multiOptionMenu = new Form.Field.MultipleOptions( "multipleOptions", "Multiple Options", [0,1,3], ["One","Two","Three"], [] ) inputForm.addField(textInput, 0) inputForm.addField(dateInput, 1) inputForm.addField(optionsMenu, 2) inputForm.addField(solitaryCheckbox, 3) inputForm.addField(multiOptionMenu, 4) formPrompt = "This is the form prompt" buttonTitle = "OK" formPromise = inputForm.show(formPrompt, buttonTitle)
Example Form
  

inputForm = new Form() textInput = new Form.Field.String("textInput", "Name", null) dateInput = new Form.Field.Date("dateInput", "Date", null) optionsMenu = new Form.Field.Option( "menu", "Position", [1,2,3], ["Top", "Middle", "Bottom"], 1 ) solitaryCheckbox = new Form.Field.Checkbox( "checkbox", "Append to selected paragraph", false ) multiOptionMenu = new Form.Field.MultipleOptions( "multipleOptions", "Multiple Options", [0,1,3], ["One","Two","Three"], [] ) inputForm.addField(textInput, 0) inputForm.addField(dateInput, 1) inputForm.addField(optionsMenu, 2) inputForm.addField(solitaryCheckbox, 3) inputForm.addField(multiOptionMenu, 4) formPrompt = "This is the form prompt" buttonTitle = "OK" formPromise = inputForm.show(formPrompt, buttonTitle)

(⬆ see above ) The resulting form on iPadOS:

Screenshot

(⬆ see above ) The resulting form on macOS:

Screenshot

Retention of Form Settings

Plug-Ins can retain and restore form settings between plug-in executions using the Preferences class (LINK).

Next

The other sections in this topic will examine how to integrate forms into actions, and how to validate and retrieve the data from a displayed form.