@bpmn-io/form-js-viewer
TypeScript icon, indicating that this package has built-in type declarations

1.15.0 • Public • Published

@bpmn-io/form-js-viewer

This library exports a form viewer for viewing and submitting forms. Use our editor to create and edit forms.

Installation

npm install @bpmn-io/form-js-viewer

Usage

import { Form } from '@bpmn-io/form-js-viewer';

const schema = {
  type: 'default',
  components: [
    {
      key: 'creditor',
      label: 'Creditor',
      type: 'textfield',
      validate: {
        required: true,
      },
    },
  ],
};

const data = {
  creditor: 'John Doe Company',
};

const form = new Form({
  container: document.querySelector('#form'),
});

await form.importSchema(schema, data);

// add event listeners
form.on('submit', (event) => {
  console.log('Form <submit>', event);
});

// provide a priority to event listeners
form.on('changed', 500, (event) => {
  console.log('Form <changed>', event);
});

Check out a full example.

Styling

For proper styling include the form-js.css stylesheet and font used:

<link
  href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,600;1,400&display=swap"
  rel="stylesheet" />

<link href="https://unpkg.com/@bpmn-io/form-js/dist/assets/form-js.css" rel="stylesheet" />

API

Form

Create a new form with options { container?: HTMLElement }.

import { Form } from '@bpmn-io/form-js-viewer';

const form = new Form({
  container: document.querySelector('#form'),
});

Form#importSchema(schema: Schema, data?: Data) => Promise<Result, Error>

Display a form represented via a form schema and the optional data.

try {
  await form.importSchema(schema);
} catch (err) {
  console.log('importing form failed', err);
}

Form#submit() => { data: Data, errors: Errors }

Submit a form programatically.

const { data, errors } = form.submit();

if (Object.keys(errors).length) {
  console.error('Form submitted with errors', errors);
}

Form#validate() => Errors

Validate a form programatically.

const errors = form.validate();

if (Object.keys(errors).length) {
  console.error('Form has errors', errors);
}

Form#reset() => void

Reset a form programatically.

Form#setProperty(key, value) => void

Set a form property such as readOnly.

Form#attachTo(parentNode: HTMLElement) => void

Attach the form to a parent node.

Form#detach() => void

Detach the form from its parent node.

Form#on(event, fn) => void

Subscribe to an event.

Form#destroy() => void

Remove form from the document.

Events

changed :: { data, errors }

Fired off every time there is a form state change.

submit :: { data, errors }

Fired off on form submission.

import.done :: { error, warnings }

Fired whenever a schema has finished importing, whether it succeeds or fails.

Layouting events

  • form.layoutCleared
  • form.layoutCalculated :: { rows }

Lifecycle Events

  • detach
  • attach
  • form.init
  • form.clear
  • form.destroy
  • diagram.clear
  • diagram.destroy

Formfield events

  • formField.add :: { formField }
  • formField.remove :: { formField }
  • formField.focus :: { formField }
  • formField.blur :: { formField }
  • formField.search :: { formField, value }

License

Use under the terms of the bpmn.io license.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.15.02,533latest

Version History

VersionDownloads (Last 7 Days)Published
1.15.02,533
1.14.1-alpha.011
1.14.0245
1.13.2287
1.13.1568
1.13.01
1.12.097
1.11.3212
1.11.24
1.11.14
1.11.02
1.10.1390
1.11.0-alpha.01
1.10.041
1.9.21
1.9.11
1.8.8420
1.8.7222
1.8.637
1.8.51
1.8.43
1.8.314
1.8.11
1.8.04
1.7.389
1.7.27
1.7.16
1.7.023
1.7.0-alpha.01
1.6.4378
1.6.31
1.6.21
1.6.11
1.6.017
1.5.013
1.5.0-alpha.03
1.4.08
1.3.31
1.3.21
1.3.013
1.3.0-alpha.01
1.1.030
1.0.04
1.0.0-alpha.101
1.0.0-alpha.91
1.0.0-alpha.75
1.0.0-alpha.61
1.0.0-alpha.51
1.0.0-alpha.41
1.0.0-alpha.31
1.0.0-alpha.11
1.0.0-alpha.01
0.15.0-alpha.01
0.14.1513
0.14.03
0.13.13
0.13.01
0.12.21
0.12.110
0.12.01
0.11.01
0.10.115
0.10.01
0.10.0-alpha.31
0.10.0-alpha.21
0.10.0-alpha.11
0.10.0-alpha.01
0.9.91
0.9.81
0.9.71
0.9.51
0.9.41
0.9.11
0.9.02
0.8.02
0.8.0-alpha.11
0.8.0-alpha.07
0.7.212
0.7.11
0.7.07
0.6.04
0.5.110
0.5.01
0.4.41
0.4.21
0.4.11
0.4.01
0.3.11
0.3.02
0.2.42
0.2.32
0.2.22
0.2.11
0.2.01
0.1.01
0.0.121
0.0.111
0.0.101
0.0.93
0.0.81
0.0.71
0.0.61
0.0.51

Package Sidebar

Install

npm i @bpmn-io/form-js-viewer

Weekly Downloads

6,344

Version

1.15.0

License

SEE LICENSE IN LICENSE

Unpacked Size

2.09 MB

Total Files

127

Last publish

Collaborators

  • bpmn-io-admin
  • nikku
  • barmac
  • philippfromme
  • maxtru
  • abdul99ahad
  • skaiir-camunda
  • vsgoulart
  • jarekdanielak
  • simon-steinruecken-camunda