SignatureField
Form field wrapper around SignaturePad with label, help text, validation, and error handling.
Component
Sign inside the box
Props
| Props | Required | Default | Type |
|---|---|---|---|
id | true | — | string |
label | — | — | string |
ariaLabel | — | — | string |
helpText | — | — | string |
helpTextPosition | — | Position.BOTTOM | Position |
required | — | false | boolean |
showOptionalLabel | — | true | boolean |
optionalLabel | — | — | string |
modelValue | — | [] | string[] |
name | — | — | string |
height | — | 200 | number |
minWidth | — | 240 | number |
strokeSize | — | 2 | number |
showGuide | — | true | boolean |
placeholder | — | 'Sign here' | string |
showClearButton | — | true | boolean |
clearIcon | — | 'mdi:eraser' | string |
clearAriaLabel | — | 'Clear signature' | string |
disabled | — | false | boolean |
readOnly | — | false | boolean |
validator | — | () => null | (value: unknown) => string | null |
error | — | '' | string |
id is the only required prop. The pad props (modelValue, name, height, minWidth, strokeSize, showGuide, placeholder, showClearButton, clearIcon, clearAriaLabel, disabled, readOnly) work as in SignaturePad.
Usage
id
Unique id of the field. The label gets ${id}-label and labels the drawing surface.
<template>
<SignatureField id="signature" label="Signature" />
</template>
label
Text of the label shown above the pad.
<template>
<SignatureField id="signature" label="Signature" />
</template>
ariaLabel
Accessible label of the pad when there is no visible label.
<template>
<SignatureField id="signature" ariaLabel="Customer signature" />
</template>
helpText
Helper text shown next to the pad. It is replaced by the error message when there is one.
<template>
<SignatureField id="signature" helpText="Sign inside the box" />
</template>
helpTextPosition
Places the help text above or below the pad.
<template>
<SignatureField id="signature" helpText="Sign inside the box" :helpTextPosition="Position.TOP" />
</template>
Options
| Value | Description |
|---|---|
TOP | top |
BOTTOM | bottom |
required
Marks the field as required, hides the optional label and enables validator.
<template>
<SignatureField id="signature" required />
</template>
showOptionalLabel
Shows the optional label when the field is not required.
<template>
<SignatureField id="signature" label="Signature" :showOptionalLabel="false" />
</template>
optionalLabel
Overrides the optional label text. Defaults to the text from the DS config.
<template>
<SignatureField id="signature" label="Signature" optionalLabel="(Optional)" />
</template>
modelValue
Strokes drawn on the pad, as a list of SVG paths.
<template>
<SignatureField id="signature" v-model="paths" />
</template>
<script setup lang="ts">
const paths = ref<string[]>([])
</script>
name
Renders a hidden input with the JSON-serialized strokes for native form submissions.
<template>
<SignatureField id="signature" name="signature" />
</template>
height
Sets the height of the pad in pixels.
<template>
<SignatureField id="signature" :height="280" />
</template>
minWidth
Sets the minimum width of the pad in pixels. Below this width the pad stops shrinking, so the container can scroll instead of squeezing the signature area.
<template>
<SignatureField id="signature" :minWidth="320" />
</template>
strokeSize
Sets the stroke width in pixels.
<template>
<SignatureField id="signature" :strokeSize="4" />
</template>
showGuide
Shows the dashed baseline to sign on.
<template>
<SignatureField id="signature" :showGuide="false" />
</template>
placeholder
Text shown over the guide while the pad is empty.
<template>
<SignatureField id="signature" placeholder="Sign inside the box" />
</template>
showClearButton
Shows the icon button that removes all strokes. It only appears once something has been drawn.
<template>
<SignatureField id="signature" :showClearButton="false" />
</template>
clearIcon
Sets the icon of the clear button.
<template>
<SignatureField id="signature" :clearIcon="'mdi:close'" />
</template>
clearAriaLabel
Sets the accessible label (aria-label) of the clear icon button.
<template>
<SignatureField id="signature" clearAriaLabel="Reset signature" />
</template>
disabled
Disables drawing and the clear button.
<template>
<SignatureField id="signature" disabled />
</template>
readOnly
Shows the strokes but prevents drawing or clearing.
<template>
<SignatureField id="signature" readOnly :modelValue="savedPaths" />
</template>
validator
Function that receives the strokes and returns an error message, or null when valid. It runs only when required is set, following the form validation mode.
<template>
<SignatureField
id="signature"
v-model="paths"
v-model:error="error"
required
:validator="value => (value as string[]).length ? null : 'Signature is required'"
/>
</template>
<script setup lang="ts">
const paths = ref<string[]>([])
const error = ref('')
</script>
error (v-model:error)
Sets the error message of the field. This prop is bindable via v-model:error, allowing two-way syncing of the validation state. It replaces the help text and applies the error border on the pad.
<template>
<SignatureField id="signature" v-model:error="errorMessage" />
</template>
Accessibility
The label is linked to the drawing surface through aria-labelledby. Without a visible label, set ariaLabel. See SignaturePad for the pointer-only note.
Emits
| Value | Description |
|---|---|
@update:modelValue | Emitted with the full list of strokes when a stroke ends or the pad is cleared (v-model). |
@update:error | Emitted with the validation message, or an empty string, when the field is validated (v-model:error). |
@draw | Emitted while drawing with `{ paths, currentPath }`. |
@draw-end | Emitted with `{ paths }` when the user finishes a stroke. |
@clear | Emitted when the pad is cleared. |
Example
<template>
<SignatureField id="signature" v-model="paths" @clear="console.log('cleared')" />
</template>
<script setup lang="ts">
const paths = ref<string[]>([])
</script>
Methods
| Value | Description |
|---|---|
clear() | Removes all strokes. |
getDataUrl(type?, quality?) | Returns the signature as a data URL. `type` defaults to `'image/png'`. |
<template>
<SignatureField id="signature" ref="fieldRef" v-model="paths" />
</template>
<script setup lang="ts">
const fieldRef = ref()
const paths = ref<string[]>([])
const exportImage = () => fieldRef.value.getDataUrl()
</script>