Modules
Describes the Form.io Module system
Modules allow developers to create encapsulated module bundles that alter the behavior of the Form.io Builder and Renderer.
Modules were introduced in formio.js v4.5.0. You need a version later than that to utilize modules. The Form.io Renderer allows for a number of plugins, which allows for external libraries the ability to alter the behavior of this library. Each plugin is defined in a module using a simple key-pair map like the following illustrates.
1
{
2
components: {...},
3
templates: {...},
4
providers: {...},
5
displays: {...}
6
}
Copied!
The following plugins can be provided within a module.
Plugin
Description
components
Allows for Custom Components to be introduced into the renderer.
templates
Allows for you to introduce new templates and CSS frameworks (such as Bootstrap, Semantic, etc)
providers
Allows for custom storage providers for file components
displays
Provides a way to provide new and override the form renderer displays.
builders
Provides a way to provide new and override the form builders
options
Allows a way to override options passed into the renderer and the builder.
fetch
Provides a way to intercept all API requests made into the Form.io renderer.
framework
Allows for the CSS framework to be forced when loaded.

Creating a module

New modules can be created by including an external Library within your application that has exports the following structure.
1
export default {
2
framework: 'semantic', // Sets the default template to a specific framework.
3
components: {
4
/* List of custom components */
5
},
6
templates: {
7
semantic: {
8
/* List of templates found @ https://github.com/formio/formio.js/blob/master/src/templates/bootstrap/index.js */
9
}
10
},
11
fetch: {
12
fetchname: CustomFetchPluginClass
13
}
14
}
Copied!
Each of the keys within this object are called Plugins and they each have their own object definitions as follows

Using a Module

Once you have a module created, it is very easy to use the module within the Form.io renderer. You simply import the module, and then use the Formio.use method to use it. The following is an example of how a module is used.
1
import { CustomModule } from './modules/custom';
2
Formio.use(CustomModule);
Copied!

Module plugins

A module consists of a bunch of plugins that are provided to the module via the "name" of the plugin. The following plugins are available for modules.

framework

This sets the default "style" framework.
Example
1
{
2
framework: 'semantic'
3
}
Copied!

components

Provides a way to override existing components, or introduce new components to the renderer/builder. Here is a simple of example of adding a new component.

components/CustomButton.js

1
import { Components } from 'formiojs';
2
const ButtonComponent = (Components as any).components.button;
3
class CustomButton extends ButtonComponent {
4
get inputInfo() {
5
const inputInfo = super.inputInfo;
6
inputInfo.attr.class += ' custom-button';
7
return inputInfo;
8
}
9
}
Copied!

module.js

1
import { CustomButton } from './components/CustomButton.js';
2
export default {
3
components: {
4
button: CustomButton
5
}
6
}
Copied!
For an example of a custom component module, take a look at the Contrib Module

templates

Introduces new templates to the renderer for use with custom components or for overriding existing templates. See Form Templates section for more details.

fetch

Allows a custom "fetch" plugin to be utilized for this renderer. All API requests will then be sent through this fetch plugin instead of the default Formio.fetch interface (which is the standard Web fetch interface). For detailed documentation, please see the Fetch Plugin API documentation.

providers

Allows the introduction of different providers as follows.
Provider
Description
storage
Storage providers allow file upload interfaces. Such as Azure Blob, Dropbox, etc. For examples, go to https://github.com/formio/formio.js/tree/master/src/providers/storage
auth
Authentication providers such as Okta, OAuth, SAML, etc. For examples, go to https://github.com/formio/formio.js/tree/master/src/providers/auth
address
Address providers such as Google Maps, Open Street Maps, etc. For examples, go to https://github.com/formio/formio.js/tree/master/src/providers/address

displays

Introduces new or overrides existing Display interfaces, such as Wizard, Form, or PDF

rules

Introduces new or overrides existing validation rules. Coming soon.

options

Allows the overriding of Form and Builder options. Must be in the following format.
1
{
2
options: {
3
form: {}, /* Provides the default options for Formio.createForm */
4
builder: {} /* Provides the default options for Formio.builder */
5
}
6
}
Copied!

Register a module

To register the module into the renderer, you must use the use method, whereas you will pass the Module definition into this method.
Example
1
import MyModule from './MyModule';
2
import { Formio } from 'formiojs';
3
Formio.use(MyModule);
Copied!

Existing Modules

Last modified 4mo ago