Creating a Client

The Forms SDK uses an instance of the CamSDK.Client to communicate with the process engine (over the REST API):

  1. var camClient = new CamSDK.Client({
  2. mock: false,
  3. apiUri: 'http://localhost:8080/engine-rest'
  4. });

Creating a Form

In order to create a form, you need to create an instance of CamSDK.Form:

  1. new CamSDK.Form({
  2. // ...
  3. });

Providing a Task Id

In case the form is a task form (i.e., the submission of the form should trigger the completing of a task), you need to provide a taskId:

  1. new CamSDK.Form({
  2. client: camClient,
  3. // the task ID
  4. taskId: 'someTaskId',
  5. //...
  6. });

Providing a Process Definition Id

In case the form is a start form (i.e., the submission of the form should trigger a new process instance to start), you need to provide a processDefinitionId:

  1. new CamSDK.Form({
  2. client: camClient,
  3. // the process definition ID
  4. processDefinitionId: 'someProcessDefinitionId',
  5. //...
  6. });

Loading a Form from a URL

The Forms SDK can automatically load forms from a URL.The URL from which the form should be loaded is referenced using the formElement property.

In that case you need to create a container element somewhere in the DOM:

  1. <div id="formContainer">
  2. </div>

And reference it in the containerElement property when creating the CamSDK.Form instance:

  1. new CamSDK.Form({
  2. client: camClient,
  3. // URL to the form
  4. formUrl: '/url/to/form.html',
  5. // the task ID
  6. taskId: 'someTaskId',
  7. // the container to which the form should be appended. Can be a DOM element or a jQuery wrapper
  8. containerElement: $('#formContainer'),
  9. done: function(error, camFormInstance) {
  10. // ..
  11. }
  12. });

Using a form existing in the DOM

It is also possible to initialize the Form SDK for a form already existing in the DOM.

Assuming that you have an HTML <form …> element present in the DOM:

  1. <form id="myForm">
  2. <input ....>
  3. </form>

You can create an instance of CamSDK.Form and attach it to the existing form like this:

  1. new CamSDK.Form({
  2. client: camClient,
  3. // the task ID
  4. taskId: 'someTaskId',
  5. // the form element. Can be a DOM element or a jQuery wrapper
  6. formElement: $('#myForm'),
  7. done: function(error, camFormInstance) {
  8. // ..
  9. }
  10. });

原文: https://docs.camunda.org/manual/7.9/reference/embedded-forms/integrate/bootstrapping/