Embedding forms

Last updated:

This article describes how Formcentric forms are embedded into a website.

Installation

As a first step, install the Formcentric client in your project:


If you want to bundle theme assets locally, you can also use the supplied dist files in the same package.

SDK integration via mount()

Embedding is established with mount(element, config) from @formcentric/client.

A simple example:


The same with a DOM element:


Browser-global defaults

In addition to the local mount(element, config) configuration, the SDK can evaluate browser-global defaults. These defaults are not Static-specific, but are also used by SDK-based integrations.

Mechanism Description
configure({...}) from @formcentric/client
Validates the browser-global defaults and replaces default values set previously.
Direct mutation of window.formcentric
Sets browser-global defaults directly on the window object. This also works without a previous configure(...) call.

Note the following:

Topic Principle
Priority
Local mount() configuration overrides browser-global defaults.
Object values
requestHeaders, themeVariables and configuration are put together from the global and local configuration. If keys are identical, the local configuration wins.
Snapshot behaviour
Browser-global defaults are read during a mount() call. Later changes do not retroactively affect instances already mounted.
Repeat configure(...)
Another call replaces browser-global defaults set previously, instead of extending them step by step.
Static only
Although dynamicInit can be set browser-global, it is not evaluated by the SDK mount itself.

The full list of the common browser-global default keys and their technical meanings are given in the main Formcentric Client General documentation.

In the SDK, important keys not set as browser-global are embedId, formDefinition, vars, params, refs, formName, instanceId and conflictBehavior.

Example:


Including bundled or local theme assets

If your application bundles theme assets itself, you import these before mounting and deactivate the runtime post-loading of the theme and templates.

Example with dist assets from @formcentric/client:


If you want to use runtime loading, either configure themeDir and theme or explicit URLs such as themeUrl, templateUrl and themeVariableUrl.

Return value and lifecycle

mount() returns a FormInstance with lifecycle methods and a ready promise.

Example:


Note the following:

ready is triggered after successful initialisation.
reload() re-initialises the form in the same container.
stop() terminates the running instance but leaves the target element in the DOM.
unmount() removes the form and performs a full cleanup for the instance.

For stricter lifecycle sequencing in the SPA code, reload(), stop() and unmount() should each be awaited.

Re-initialisation and configuration changes

The SDK integration is restart-based. Configuration values are applied on initialisation and not carried across live to a running instance automatically.

If you change configuration values, the embedding should be re-established explicitly. By await form.unmount() followed by a repeat mount(), for example, or via await form.reload() if container and identity should intentionally remain the same.

Note the following:

  1. Changes to embedId or formDefinition should normally lead to a fresh mount.
  2. In cases where handover between instances is desired, embedId should remain stable and conflictBehavior: 'stop-existing' should be set.
  3. For other configuration changes, a controlled remount should take place instead of expecting live updates.

Events and troubleshooting

For simple integration projects, optional callbacks can be passed directly in the configuration:

  1. onReady: is called after successful initialisation
  2. onError: is called after initialisation errors or runtime errors

Example:


onReady signals that the initialisation has been successfully completed. This is not a dedicated signal for an initial visible render timestamp.

Feedback