Create a basic plugin using Lit

You can use any modern web component framework to build Form plugins. In this example, we will build a basic plugin in a single JavaScript file that displays some static HTML. We will build the standard web component first using Lit, and then add the Form plugin contract to convert it to a plugin.

Jump to:

Import the lit library

  1. Create a JavaScript file.
  2. Import the HTML element class we want to use from the Lit library CDN.

import { html,LitElement} from 'https://cdn.jsdelivr.net/gh/lit/dist@2/all/lit-all.min.js';

Define the web component

  1. Define the web component as an extension of the HTML element we imported.
  2. Add a variable elementName.
  3. The elementName you choose will be used as the HTML tag for the plugin in the DOM, as well as to identify the plugin during the plugin registration. See Add a plugin.

    Note:  Your plugin element name must contain a hyphen - and must not start with ntx-, nwc-, nac-, or nintex-. These prefixes are reserved to prevent conflicts with Nintex elements. For best practice, use your organization's name as a prefix. For example, acme-custom-textfield.

  4. Define your web component with customElement.define().

export class HelloWorld extends LitElement {

}

const elementName = 'hello-world';
customElements.define(elementName, HelloWorld);

Add the render function

Add a render function to return the HTML the plugin will display in the form.


export class HelloWorld extends LitElement {
  static properties = {
    who: {type: String},
  };
	
  constructor() {
    super();
    this.who = 'World';
  }						
							
  render() {
    return html`<p>Hello ${this.who}<p/>`;
  }
}
//...

Add the contract properties

  1. In the web component class constructor, add an asynchronous static function getMetaConfig().
  2. Return an object with the contract properties for your plugin.
  3. If you have custom fields that should connect to reactive properties in your plugin, make sure they use the same name. See Create a custom configuration field.

Note: The controlName and version properties must be set for your plugin.

See Plugin properties reference for other properties.


export class CustomInput extends LitElement {
  
  static getMetaConfig() {
    return {
      controlName: 'Hello World',
      fallbackDisableSubmit: false,
      version: '1.2',
      properties: {
        who: {
          type: 'string',
          title: 'Who',
          description: 'Who to say hello to'
        }
      }
    };
  }						
  //...

}

The completed plugin


import { html,LitElement} from 'https://cdn.jsdelivr.net/gh/lit/dist@2/all/lit-all.min.js';
// define the component
export class HelloWorld extends LitElement {
  
  static properties = {
    who: {type: String},
  };
  
  // return a promise for contract changes.
  static getMetaConfig() {
    return {
      controlName: 'Hello World',
      fallbackDisableSubmit: false,
      version: '1.2',
      properties: {
        who: {
          type: 'string',
          title: 'Who',
          description: 'Who to say hello to'
        }
      }
    };
  }
  
  constructor() {
    super();
    this.who = 'World';
  }

  render() {
    return html`<p>Hello ${this.who}<p/>`;
  }
}

// registering the web component
const elementName = 'hello-world';
customElements.define(elementName, HelloWorld);
		

Upload and register your plugin

Upload this plugin to your hosting service and register it in your tenant. See:

What's next...

Now that you've completed a basic plugin, explore some more examples:

If you want to jump straight in to create your own plugin, see how to:

Or see the Plugin properties reference.