- Undo and Redo
- Clear
- Disabled
- ReadOnly
Contact Support
User Interactions
6 Apr 20228 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.
Clear
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.
Disabled
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.
ReadOnly
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.
<div class='wrap'>
<div id="option">
<table>
<tr>
<td>
<ejs-button id="undoBtn" cssClass="e-primary" content="Undo" disabled="true"></ejs-button>
</td>
<td>
<ejs-button id="redoBtn" cssClass="e-primary" content="Redo" disabled="true"></ejs-button>
</td>
<td>
<ejs-button id="clearBtn" cssClass="e-primary" content="Clear" disabled="true"></ejs-button>
</td>
<td>
<div style="margin-bottom: 5px; margin-left: 200px;">
<ejs-checkbox id="disable" label="Disabled" change="disableChange"></ejs-checkbox>
</div>
<div style="margin-left: 200px;">
<ejs-checkbox id="readonly" label="ReadOnly" change="readOnlyChange"></ejs-checkbox>
</div>
</td>
</tr>
</table>
</div>
<div id="signature-control">
<ejs-signature id="signature" change="change"></ejs-signature>
</div>
</div>
<script>
document.getElementById("undoBtn").addEventListener('click', function () {
var signature = document.getElementById("signature").ej2_instances[0];
if (!signature.isReadOnly && !signature.disabled) {
signature.undo();
}
});
document.getElementById("redoBtn").addEventListener('click', function () {
var signature = document.getElementById("signature").ej2_instances[0];
if (!signature.isReadOnly && !signature.disabled) {
signature.redo();
}
});
document.getElementById("clearBtn").addEventListener('click', function () {
var signature = document.getElementById("signature").ej2_instances[0];
if (!signature.isReadOnly && !signature.disabled) {
signature.clear();
}
});
function disableChange(args) {
var signature = document.getElementById("signature").ej2_instances[0];
signature.disabled = args.checked;
}
function readOnlyChange(args) {
var signature = document.getElementById("signature").ej2_instances[0];
signature.isReadOnly = args.checked;
}
function change() {
var signature = document.getElementById("signature").ej2_instances[0];
var undoBtn = document.getElementById("undoBtn").ej2_instances[0];
var redoBtn = document.getElementById("redoBtn").ej2_instances[0];
var clearBtn = document.getElementById("clearBtn").ej2_instances[0];
if (!signature.disabled && !signature.isReadOnly) {
if (signature.canUndo()) {
undoBtn.disabled = false;
} else {
undoBtn.disabled = true;
}
if (signature.canRedo()) {
redoBtn.disabled = false;
} else {
redoBtn.disabled = true;
}
if (!signature.isEmpty()) {
clearBtn.disabled = false;
} else {
clearBtn.disabled = true;
}
}
}
</script>
<style>
.wrap {
margin: 0 auto;
width: 500px;
text-align: center;
}
#signature {
border: 1px solid lightgray;
height: 100%;
width: 100%;
}
#option {
margin-bottom: 10px;
}
</style>
public ActionResult Default()
{
return View();
}
Output be like the below.