User interaction in EJ2 JavaScript Signature control

15 May 20239 minutes to read

The below interactions were available in Signature, and we can walk through one by one.

  • Undo and Redo
  • Clear
  • Disabled
  • ReadOnly

Undo and Redo

In the Signature, every action can be maintained as a snap for undo and redo operations. And maintained SnapIndex for indexing the snap collection.

The undo method reverts the last action of signature by decreasing SnapIndex value to index previous snap. Here, canUndo method is used to ensure whether undo can be performed or not.

The redo method reverts the last undo action of the signature by increasing the SnapIndex to get the next snap. Here, canRedo method is used to ensure whether redo can be performed or not.


The clear method is used to clears the signature and makes the canvas empty. This is also considered in Undo/ Redo. Here, isEmpty method is used to ensure whether the signature is empty or not.


The disabled property is used to enables/disables the signature control. In the disabled state, the user is not allowed to draw signature. And it can’t be focused until the user enabled the signature.


The isReadOnly property is used to enables/disables the ReadOnly Signature. It can be focused but it prevents drawing in Signature.

The following sample explains about user interactions available in signature.

ej.base.enableRipple = true;

var signature = new ej.inputs.Signature({change: changeEvent}, '#signature');

var undoButton = new ej.buttons.Button({cssClass: 'e-primary', disabled: true}, '#undo');
undoButton.element.onclick = function (e) {
    if (!signature.disabled && !signature.isReadOnly) {

var redoButton = new ej.buttons.Button({cssClass: 'e-primary', disabled: true}, '#redo');
redoButton.element.onclick = function (e) {
    if (!signature.disabled && !signature.isReadOnly) {

var clearButton = new ej.buttons.Button({cssClass: 'e-primary', disabled: true}, '#clear');
clearButton.element.onclick = function (e) {
    if (!signature.disabled && !signature.isReadOnly) {

var checkBox1 = new ej.buttons.CheckBox({ label: 'Disabled', change: onChangeDisable}, '#disable');
function onChangeDisable(args) {
    signature.disabled = args.checked;

var checkBox2 = new ej.buttons.CheckBox({ label: 'ReadOnly', change: onChangeReadonly}, '#readonly');
function onChangeReadonly(args) {
    signature.isReadOnly = args.checked;

function changeEvent(args) {
    if (!signature.disabled && !signature.isReadOnly) {
        if (signature.canUndo()) {
            undoButton.disabled = false;
        } else {
            undoButton.disabled = true;
        if (signature.canRedo()) {
            redoButton.disabled = false;
        } else {
            redoButton.disabled = true;
        if (!signature.isEmpty()) {
            clearButton.disabled = false;
        } else {
            clearButton.disabled = true;
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Signature</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="TypeScript Signature Component">
    <meta name="author" content="Syncfusion">
    <link href="styles.css" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="" type ="text/javascript"></script>
    <div id="container">
        <div id="option">
                        <button id="undo" style="margin-right: 20px;">UNDO</button>
                        <button id="redo" style="margin-right: 20px;">REDO</button>
                        <button id="clear" style="margin-right: 200px;">CLEAR</button>
                        <div style="margin-bottom: 5px;"><input id="disable" type="checkbox"></div>
                        <div><input id="readonly" type="checkbox"></div>
        <div id="signature-control">
            <canvas id="signature" style="height: 100%; width: 100%;"></canvas>

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>
#container {
  visibility: hidden;

#loader {
  color: #008cff;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;

#signature-control {
  height: 300px;
  width: 550px;

#signature {
  border: 1px solid lightgray;

#option {
  margin-bottom: 10px;