Skip to main content

Introducing Workflow Engine, try for FREE workflowengine.io.

Signature

Introduction​

The Signature component is a drawing pad where users sign with a mouse, touchpad, or touch screen. Typical uses include consent forms and contracts.

It lives in a separate package, @react-form-builder/components-signature, under a commercial license. For commercial use, contact sales@optimajet.com.

Signature field on the Designer canvas with Main properties open.

The pad value is a PNG data URL string. On the Main tab you can set the label, canvas size, pen color and thickness, background color, and Clear button text.

Installation​

npm install @react-form-builder/components-signature

You also need @react-form-builder/core and, for the designer, @react-form-builder/designer. The examples below assume you already use @react-form-builder/components-rsuite and add Signature next to those components.

Connection to FormBuilder​

Register signatureComponent in a BuilderView so Signature appears in the palette:

import {rSuiteComponents} from '@react-form-builder/components-rsuite'
import {BuilderView, FormBuilder} from '@react-form-builder/designer'
import {signatureComponent} from '@react-form-builder/components-signature'

const components = rSuiteComponents.map(c => c.build())
const builderView = new BuilderView([...components, signatureComponent.build()])

function App() {
return <FormBuilder view={builderView} />
}

You can pass signatureComponentsDescriptions (or a localized map) with .withComponentLibraryDescription(...) so Designer property labels match your UI language. See the API reference.

Signature selected in the component palette under Fields.

Connection to FormViewer​

Register signatureModel on a View (or use signatureComponent.build().model):

import {signatureModel} from '@react-form-builder/components-signature'
import {rSuiteComponents} from '@react-form-builder/components-rsuite'
import {FormViewer, View} from '@react-form-builder/core'

const components = [
...rSuiteComponents.map(c => c.build().model),
signatureModel,
]
const view = new View(components)

const form = `{
"form": {
"key": "Screen",
"type": "Screen",
"props": {},
"children": [
{
"key": "signature",
"type": "RsSignature",
"props": {
"label": { "value": "Sign here" },
"width": { "value": 370 },
"height": { "value": 200 }
}
}
]
}
}`

function App() {
return <FormViewer view={view} getForm={() => form} />
}

In form JSON the type is RsSignature. The valued property is value (data URL). An onChange handler receives the new data URL after each stroke or when the user clears the pad.

Signature pad in Preview after the user draws a signature.

Sample form JSON​

Example with common Main-tab settings:

{
"form": {
"key": "Screen",
"type": "Screen",
"props": {},
"children": [
{
"key": "signature",
"type": "RsSignature",
"props": {
"label": { "value": "Authorized signature" },
"clearButtonText": { "value": "Clear" },
"width": { "value": 370 },
"height": { "value": 200 },
"lineWidth": { "value": 1.5 },
"penColor": { "value": "rgba(0, 0, 0, 1)" },
"backgroundColor": { "value": "rgba(167, 167, 167, 0.1)" },
"readOnly": { "value": false }
}
}
]
}
}

Main properties​

The following general properties are available within the Main tab:

NameTypeDescription
ValuestringInitial data URL for the signature image
LabelstringText displayed above the pad
Clear Button TextstringLabel for the Clear button
WidthnumberCanvas width in pixels
HeightnumberCanvas height in pixels
Line WidthnumberPen stroke thickness
Pen colorcolorPen stroke color
Background colorcolorCanvas background color
Read OnlybooleanWhen true, disables drawing and hides the Clear button

At the bottom of the Main properties menu, you can find additional options:

Style properties​

These are properties that allow to customize the size, color and other style properties of your component:

  • For Device: You can provide component's style customization for all devices or specific devices by using this dropdown list. Refer to Adaptive Layout for more details.
  • Component > Class Name: Add a class name for your component for the subsequent styling if necessary.
  • Wrapper: The options below enable you to tailor the appearance of your component and customize it for a specific device type, as selected in the For Device property:

    NameTypeDescription
    WidthnumberSpecifies the width for your component
    HeightnumberSpecifies the height for your component
    Margin top/right/bottom/leftnumberMargin values for you component
    ColorstringAllows customizing the text color
    Background colorstringEnables customizing the background color

For more information, see the API reference for components-signature.