Orbeon Forms
  • Getting started
  • Installation
    • Logging
    • Configuration banner
    • Docker
    • Azure
    • Tomcat
    • WildFly
    • WebSphere
    • WebLogic
    • GlassFish
    • Caches
    • Replication
    • Upgrading
  • Configuration
    • Properties
      • General
        • HTTP client
      • Form Runner
        • Detail page
          • Attachments
          • Email properties
          • PDF
          • Table of contents
        • Persistence
        • Summary page
      • Form Builder
      • XForms
    • Advanced
      • Workflows
      • Session management
      • State handling
      • Client-side error handling
      • Clustering and High Availability
      • Configuring a Form Runner eXist database
      • Creating a production WAR
      • Environments
      • JavaScript and CSS assets
      • Limiter filter
      • Run modes
      • Security
        • Content-Security-Policy header
      • SAP Hybris Module
      • XForms logging
    • Troubleshooting
      • Troubleshooting with the orbeon.log
      • Memory and threads
      • Relational database logging
      • Misc
  • Form Builder
    • Form settings
      • Time window
    • Form editor
      • Form area
      • Toolbox
      • Buttons bar
      • Control settings
      • Dependent fields and sections
      • Validation
      • Choices editor
      • Publishing
      • Cut, copy and paste
      • Section and grid settings
      • Section settings
      • Grid settings
      • Quick control search
      • Repeat settings
      • Repeated grids
      • Undo and redo
      • Keyboard shortcuts
    • Formulas
      • Examples of formulas
      • Formulas inspector
      • Formulas console
    • Summary page
    • Form localization
    • Advanced
      • Edit source
      • Services and actions
        • HTTP services
        • Database services
        • Simple Actions
        • Action Syntax
        • Action Syntax examples
        • Synchronizing repeated content
      • Testing a form in web mode
      • Testing PDF production
      • Testing offline functionality
      • Email Settings dialog
      • Field-level encryption
      • Messages
      • Section templates
      • Template syntax
      • XML Schemas support
      • Extensibility
        • Extension API
        • Integration
        • Toolbox component metadata
  • Form Runner
    • Overview
      • Terminology
    • Pages
      • Landing page
      • Published Forms page
      • Forms Admin page
      • Summary page
    • Components
      • Alert dialog
      • Attachment
      • Autocomplete
      • Captcha
      • Character counter
      • Checkbox input
      • Currency
      • Date
      • Dropdown date
      • Static and dynamic dropdown
      • Error summary
      • Grid
      • Handwritten signature
      • Hidden field
      • Image
      • Image annotation
      • Image attachment
      • Number
      • Open selection
      • Repeater
      • Formatted Text / Rich Text Editor
      • Section
      • Single-selection tree
      • Source code editor
      • Time
      • US phone
      • US state
      • Video
      • Video attachment
      • Wizard
      • XForms inspector
      • Yes/No answer
    • Features
      • Automatic calculations dependencies
      • Datasets
      • Excel and XML import
      • Excel and XML export
      • Summary page Excel Export
      • Form definitions and form data Zip Export
      • Purging historical data
      • Lease
      • Localization
      • Supported languages
      • Mobile support
      • Multitenancy
      • Form Runner navigation bar
      • PDF production
        • Automatic PDF
        • Automatic PDF header and footer configuration
        • PDF templates
      • Responsive design
      • Revision history
      • S3 storage
      • Simple data migration
      • TIFF production
      • Versioning
      • Wizard view
      • Workflow stage
    • Persistence
      • Using a relational database
      • Relational database schema
      • Purging old data using SQL
      • Auditing
      • Autosave
      • Database support
      • Flat view
    • Linking and embedding
      • Linking
      • Java Embedding API
      • JavaScript Embedding API
      • Liferay full portlet
      • Liferay proxy portlet
      • Securing Form Runner access
      • Form Runner offline embedding API
      • Angular component
      • React component
    • Access control and permissions
      • Users
      • Login & Logout
      • Deployed forms
      • Form fields
      • Editing forms
      • Owner and group member
      • Organizations
      • Scenarios
      • Token-based permissions
    • Styling
      • CSS
      • Grids CSS
      • Automatic PDF styling and CSS
    • APIs
      • Authentication of server-side service APIs
      • Persistence API
        • CRUD API
        • Search API
        • List form data attachments API
        • Form Metadata API
        • Lease API
        • Reindexing API
        • Caching
        • Versioning
        • Revision History API
        • Zip Export API
        • Custom persistence providers
      • Other APIs
        • Connection context API
        • Duplicate form data API
        • File scan API
        • Form Runner JavaScript API
        • Generate XML Schema API
        • PDF API
        • Publish form definition API
        • Run form in the background API
      • Data formats
        • Form data
        • Date and time
        • Form definition
    • Architecture and integration
      • Architecture
      • Access form data
      • Integration
    • Advanced
      • Buttons and processes
        • Simple process syntax
        • Core actions
        • Form Runner actions
          • Save action
          • Send action
          • Email action
        • XForms actions
        • Predefined buttons, processes and dialogs
        • Summary page buttons and processes
      • Custom dialogs/model logic
      • Services
      • Singleton form
      • Monitoring HTTP requests
  • XForms
    • Core
      • Attribute Value Templates (AVTs)
      • Binds
      • Validation
      • Variables
      • Keyboard focus
      • XForms JavaScript API
      • Error handling
        • Detailed behavior
      • Model-Bind variables
      • XForms 2.0 support
    • Events
      • Standard support
      • UI refresh events
      • Keyboard events
      • Extension events
      • Extension context information
      • Other event extensions
    • Actions
      • Repeat, insert and delete
      • Scripting actions
      • Extensions
    • Controls
      • Label, hint, help
      • Input
      • Output
      • Text area
      • Button
      • Upload
      • Dialog
    • Submission
      • Standard support
      • JSON support
      • Asynchronous submissions
      • Caching extension
      • Other submission extensions
    • XPath
      • Type annotations
      • Expression analysis
      • Tips
      • Compatibility
      • Standard functions
      • Maps and arrays Functions
      • Extension functions
        • Core functions
        • Utility functions
        • Model functions
        • Controls functions
        • XML functions
        • JSON functions
        • HTTP functions
        • Form Runner functions
        • Other functions
        • Deprecated functions
    • XBL components
      • FAQ
      • Guide
        • XBL Tutorial
        • Bindings
        • XForms models
        • Including content
        • Event handling
        • Conventions
        • Map XBL example
        • Learning from existing components
      • Advanced topics
        • XBL Modes
        • JavaScript companion classes
        • XBL library
        • Extensions
        • Attachment controls
    • XForms tutorial
      • Introduction
      • Installation
      • The Hello application
      • The Bookcast application
        • The basic app
        • Database access
        • Polishing the app
        • Adding a feed
    • Using XForms from Java apps
  • XML Platform
    • Page Flow Controller
      • Basics
      • XML submission
      • Navigating between pages
      • Paths and matchers
      • Other configuration elements
      • Typical combinations of page model and page view
      • Examples
      • Authorizing pages and services
    • Processors
      • URL generator
      • Request generator
      • PDF to image converter
    • Resources
      • Resource managers
      • Setting up an external resources directory
    • Other
      • Binary and text documents
  • FAQ
    • Licensing
    • PE and Dev Support
    • Form Builder and Form Runner
    • Resources and support
    • Other technical questions
  • Contributors
    • Automated tests
    • Building Orbeon Forms
    • Localizing Orbeon Forms
    • Validation functions
    • Contributor License Agreement
  • Release notes
    • Orbeon Forms 2022.1.9
    • Orbeon Forms 2024.1.1
    • Orbeon Forms 2023.1.7
    • Orbeon Forms 2024.1
    • Orbeon Forms 2023.1.6
    • Orbeon Forms 2023.1.5
    • Orbeon Forms 2021.1.11
    • Orbeon Forms 2022.1.8
    • Orbeon Forms 2023.1.4
    • Orbeon Forms 2023.1.3
    • Orbeon Forms 2023.1.2
    • Orbeon Forms 2022.1.7
    • Orbeon Forms 2023.1.1
    • Orbeon Forms 2023.1
    • Orbeon Forms 2022.1.6
    • Orbeon Forms 2021.1.10
    • Orbeon Forms 2022.1.5
    • Orbeon Forms 2021.1.9
    • Orbeon Forms 2022.1.4
    • Orbeon Forms 2022.1.3
    • Orbeon Forms 2021.1.8
    • Orbeon Forms 2022.1.2
    • Orbeon Forms 2022.1.1
    • Orbeon Forms 2022.1
    • Orbeon Forms 2021.1.7
    • Orbeon Forms 2021.1.6
    • Orbeon Forms 2021.1.5
    • Orbeon Forms 2021.1.4
    • Orbeon Forms 2021.1.3
    • Orbeon Forms 2021.1.2
    • Orbeon Forms 2021.1.1
    • Orbeon Forms 2021.1
    • Orbeon Forms 2020.1.6
    • Orbeon Forms 2019.2.4
    • Orbeon Forms 2019.1.2
    • Orbeon Forms 2018.2.5
    • Orbeon Forms 2018.1.4
    • Orbeon Forms 2020.1.5
    • Orbeon Forms 2020.1.4
    • Orbeon Forms 2020.1.3
    • Orbeon Forms 2020.1.2
    • Orbeon Forms 2019.2.3
    • Orbeon Forms 2020.1.1
    • Orbeon Forms 2020.1
    • Orbeon Forms 2019.2.2
    • Orbeon Forms 2019.2.1
    • Orbeon Forms 2019.1.1
    • Orbeon Forms 2019.2
    • Orbeon Forms 2019.1
    • Orbeon Forms 2018.2.4
  • Release history
  • Use cases
  • Product roadmap
  • Index of features
Powered by GitBook
On this page
  • Getting a reference to a form
  • Identifying a form by id or element
  • The FormRunnerForm object
  • Finding a Form Runner control by name
  • Setting a control's value
  • Getting a control's value
  • Activating a form control
  • Telling whether the form data is safe
  • Activating a process button
  • Adding and removing process callback functions
  • Finding a Form Runner control by name
  • Setting a control's value
  • Telling whether the form data is safe
  • Focusing on a control
  • Listening for Error Summary navigation
  • See also
  1. Form Runner
  2. APIs
  3. Other APIs

Form Runner JavaScript API

PreviousFile scan APINextGenerate XML Schema API

Last updated 1 month ago

Getting a reference to a form

You can get a reference to an object representing a Form Runner form with the getForm() function:

ORBEON.fr.API.getForm(formIdOrElem: string | HTMLElement): FormRunnerForm

The formIdOrElem parameter is described .

Identifying a form by id or element

The formIdOrElem parameter used in APIs can be:

  • missing or undefined: this searches for the first Orbeon Forms form on the page

  • a string: this is the namespaced id of the form

  • an HTML element: this is the HTML form element, or a descendant or an HTML form element

If the form is not found, null is returned. If found, an object is returned, which contains methods described below.

The FormRunnerForm object

Finding a Form Runner control by name

The findControlsByName() function returns the HTML element(s) corresponding to the given Form Runner control name.

NOTE: The control must be visible or it will not be found. In particular, if the control is in a hidden wizard page, the control will not be found.

A Form Runner control name is the name entered by the form author in Form Builder. Examples:

  • first-name

  • street-address

function findControlsByName(
    controlName : string
): HTMLElement[]
Name
Required
Type
Description

controlName

Yes

string

The name of the Form Runner control.

If no control is found, an empty array is returned.

If there are multiple controls with the same name, the array will contain multiple elements. This can happen in the following cases:

  • when controls are repeated, for example in a repeated grid or section

  • when controls appear in the main form and section template and/or in different section templates

On the other hand, if the control exists but is not shown at a given time, for example if it is in a hidden wizard page, the array will be empty.

Example:

ORBEON.fr.API.getFOrm().findControlsByName('street-address')

Setting a control's value

The setControlValue() function allows you to set the value of a Form Runner control.

function setControlValue(
    controlName : string,
    controlValue: string | int,
    index       : int[]
): Promise<void> | undefined
Name
Required
Type
Description
Since

controlName

Yes

string

The name of the Form Runner control

2023.1

controlValue

Yes

string | int

The value to set

2023.1 (2024.1.2 for int)

index

No

int[] | undefined

If specified, and the control is repeated, the 0-based position of the control

2023.1.1

Here is how to set the value of a text field called my-field to the value "Hello!":

ORBEON.fr.API.getForm().setControlValue('my-field', 'Hello!')

For single selection controls, pass the index of the item to select:

ORBEON.fr.API.getForm().setControlValue('my-single-selection', '2')

For multiple selection controls, pass a space-separated string of item indexes:

ORBEON.fr.API.getForm().setControlValue('checkboxes', '0 1 3')

The following controls are supported:

  • Text field

  • Plain text area

  • Dropdown

  • Checkboxes

  • Radio buttons

  • Number

  • Currency

  • Date

  • Time

The setControlValue() function returns either:

  • a JavaScript Promise which resolves when the value is set on the server

  • or undefined if

    • the control is not found

    • the control is an XBL component which doesn't support the JavaScript lifecycle

If a control is repeated, use the optional index parameter to specify which repetition to set. The index is 0-based.

ORBEON.fr.API.getForm().setControlValue('my-repeated-control', 'Anvil', 3)

For single-selection controls, you can also pass an integer value rather than a string:

ORBEON.fr.API.getForm().setControlValue('my-single-selection', 2)

Getting a control's value

The getControlValue() function allows you to get the value of a Form Runner control.

function getControlValue(
    controlName : string,
    index       : int[]
): string | undefined
Name
Required
Type
Description
Since

controlName

Yes

string

The name of the Form Runner control

2024.1.2

index

No

int[] | undefined

If specified, and the control is repeated, the 0-based position of the control

2024.1.2

Here is how to get the value of a text field called my-field:

ORBEON.fr.API.getForm().getControlValue('my-field')

The getControlValue() function returns either:

  • a string with the value of the control

  • or undefined if

    • the control is not found

    • the control is an XBL component which doesn't support the JavaScript lifecycle

Activating a form control

The activateControl() function allows you to activate a Form Runner control. This is useful to activating buttons that are present within the form (as opposed to process buttons, which are typically placed at the bottom of the form). However, you can also activate other controls, in particular Text Fields.

function activateControl(
    controlName: string
): Promise<void>
Name
Required
Type
Description

controlName

Yes

string

The name of the Form Runner control

The following controls are supported:

  • Text field (as if the user presses the Return or Enter key)

  • Button

The activateControl() function returns either:

  • a JavaScript Promise which resolves when the activation has run on the server

  • or undefined if

    • the control is not found

    • the control is not a trigger or input control

Telling whether the form data is safe

function isFormDataSafe(): boolean

Orbeon Forms supports the notion that form data can be "safe" or not: specifically, it is safe if it's been saved to a database.

This function allows you to tell whether the data is safe or not.

Example:

ORBEON.fr.API.getForm().isFormDataSafe()

Activating a process button

function activateProcessButton(buttonName: string): void

Process buttons are typically buttons that are not directly part of the form, but placed at the bottom of the form. They include functions such as "Save", "Send", "Next", etc.

You can activate a process button with this function by specifying the button name. Example:

ORBEON.fr.API.getForm().activateProcessButton("wizard-next")

Adding and removing process callback functions

You add a callback function on the client using:

function addCallback(name: string, fn: () => void): void
Name
Required
Type
Description

name

Yes

string

Name passed to the server-side callback() action

fn

Yes

() => void

Callback function to be called on the client

You remove a callback function on the client using:

function removeCallback(name: String, fn: () => void): void

The name and fn parameters must be the same as those passed to addCallback().

Finding a Form Runner control by name

[SINCE Orbeon Forms 2017.2]

The findControlsByName() function returns the HTML element(s) corresponding to the given Form Runner control name.

ORBEON.fr.API.findControlsByName(
    controlName  : string, 
    formIdOrElem?: HTMLElement
): HTMLElement[]
Name
Required
Type
Description

controlName

Yes

string

The name of the Form Runner control.

formIdOrElem

No

formIdOrElem: string | HTMLElement

Prefer using first the getForm() function, and then, on the object returned, the findControlsByName() function.

Setting a control's value

For example, here is how to set the value of a text field called my-field to the value "Hello!":

ORBEON.xforms.Document.setValue(
    ORBEON.fr.API.findControlsByName('my-field')[0],
    'Hello!'
)

NOTE: For dropdowns created with Form Builder, the API does not provide direct support as of Orbeon Forms 2019.1. You can do it with the following JavaScript:

ORBEON.xforms.Document.setValue(
    ORBEON.fr.API.findControlsByName('my-dropdown')[0].querySelector(".xforms-select1"),
    1
)

Where the value you pass corresponds to the position of the item starting at 0.

Prefer using first the getForm() function, and then, on the object returned, the setControlValue() function.

Telling whether the form data is safe

[SINCE Orbeon Forms 2019.2]

ORBEON.fr.API.isFormDataSafe(
    formIdOrElem: string | HTMLElement
): boolean
Name
Required
Type
Description

formIdOrElem

No

formIdOrElem: string | HTMLElement

Prefer using first the getForm() function, and then, on the object returned, the isFormDataSafe() function.

Focusing on a control

[SINCE Orbeon Forms 2017.2]

The wizard.focus() function sets keyboard focus on a Form Runner control by name, including toggling wizard pages first if needed.

ORBEON.fr.API.wizard.focus(
    controlName   : String,
    repeatIndexes : Int[]?
)
Name
Required
Type
Description

controlName

Yes

string

The name of the Form Runner control.

repeatIndexes

No

array of Int

Repeat indexes.

This function doesn't have any effect if the control is readonly or non-relevant.

Example:

ORBEON.fr.API.wizard.focus('street-address')

The optional repeatIndexes parameter allows reaching controls within repeats. For example, with one level of repeat:

ORBEON.fr.API.wizard.focus('comment', [ 2 ])

accesses the second iteration of the comment field.

Similarly, for nested repeats, you add as many elements in the array as there are nested repeats:

ORBEON.fr.API.wizard.focus('comment', [ 3, 2 ])

When repeatIndexes is not specified, if the field is repeated, a single field is selected following the current repeat indexes.

NOTE: This only supports the wizard's free validation mode. lax and strict are not yet supported.

This now also works with the strict and lax validation modes. In these modes, the wizard will check whether the switch to the requested wizard page is allowed.

  • If so, it will switch and focus on the control.

  • If not, it will ignore the focus() request.

Listening for Error Summary navigation

[SINCE Orbeon Forms 2022.1]

For analytics purposes, it can be useful to capture when the user is interacting with the Error Summary.

You can do so with the errorSummary.addNavigateToErrorListener() function:

ORBEON.fr.API.errorSummary.addNavigateToErrorListener(
    listener: (e: ErrorSummaryNavigateToErrorEvent) => void
)

Example:

ORBEON.fr.API.errorSummary.addNavigateToErrorListener(
    function(e) { console.log(e); }
)

The parameter to the function is an event object defined as follows:

type ErrorSummaryNavigateToErrorEvent = {
    readonly validationPosition: number;   // positive integer
    readonly controlName       : string;   // Form Runner control name
    readonly repetitions       : number[]; // 1-based repeat indexes if within repeated grids/sections
    readonly controlLabel      : string;   // control label in the current language
    readonly validationMessage : string;   // validation message in the current language
    readonly validationLevel   : string;   // "error", "warning", or "info"
    readonly sectionNames      : string[]; // ancestor section names
    readonly elementId         : string;   // id of the element in the DOM (can be missing from the DOM!)
}

The listener can be removed with removeNavigateToErrorListener() by passing the same function object as parameter.

ORBEON.fr.API.errorSummary.removeNavigateToErrorListener(fn)

See also

See also .

Form Runner simple processes now support a server action that allows client-side callback functions to be called.

See

You can set a control's value using the .

See

[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1.1]
[SINCE Orbeon Forms 2024.1.2]
[SINCE Orbeon Forms 2024.1.2]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1.1]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
XForms JavaScript API
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1.2]
XForms JavaScript API
[SINCE Orbeon Forms 2023.1]
[SINCE Orbeon Forms 2023.1]
below
Identifying a form by id or element
Identifying a form by id or element
the set-data-status action
callback() action
Adding your own JavaScript