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

1.12.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.12.0961latest

Version History

VersionDownloads (Last 7 Days)Published
1.12.0961
1.11.3919
1.11.23,103
1.11.120
1.11.06
1.10.1688
1.11.0-alpha.04
1.10.0137
1.9.20
1.9.19
1.8.8181
1.8.7366
1.8.632
1.8.50
1.8.40
1.8.357
1.8.130
1.8.00
1.7.3444
1.7.20
1.7.135
1.7.0155
1.7.0-alpha.00
1.6.4544
1.6.331
1.6.20
1.6.10
1.6.032
1.5.05
1.5.0-alpha.01
1.4.032
1.3.367
1.3.20
1.3.040
1.3.0-alpha.00
1.1.01
1.0.00
1.0.0-alpha.106
1.0.0-alpha.91
1.0.0-alpha.70
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.1394
0.14.01
0.13.125
0.13.01
0.12.24
0.12.11
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.52
0.9.41
0.9.11
0.9.01
0.8.05
0.8.0-alpha.12
0.8.0-alpha.07
0.7.216
0.7.11
0.7.02
0.6.01
0.5.15
0.5.01
0.4.41
0.4.21
0.4.11
0.4.02
0.3.11
0.3.01
0.2.45
0.2.31
0.2.21
0.2.11
0.2.01
0.1.01
0.0.121
0.0.111
0.0.101
0.0.92
0.0.81
0.0.71
0.0.61
0.0.52

Package Sidebar

Install

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

Weekly Downloads

8,437

Version

1.12.0

License

SEE LICENSE IN LICENSE

Unpacked Size

2.01 MB

Total Files

126

Last publish

Collaborators

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