Skip to content

Commit 81ea54a

Browse files
committed
Added "clear" button to the signature pad
1 parent e16319a commit 81ea54a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/signature_pad.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ function init(Survey) {
88
widgetIsLoaded: function() {
99
return typeof SignaturePad != "undefined";
1010
},
11-
penColor: "1ab394",
11+
penColor: "#1ab394",
1212
isFit: function(question) {
1313
return question.getType() === "signaturepad";
1414
},
15-
htmlTemplate: "<div></div>",
15+
htmlTemplate:
16+
"<div class='sjs_sp_container'><div><canvas></canvas></div><div class='sjs_sp_controls'><button type='button' class='sjs_sp_clear' title='Clear'>✖</button></div></div><style>.sjs_sp_container { position: relative; } .sjs_sp_controls { position: absolute; left: 0; bottom: 0; } .sjs_sp_controls > button { user-select: none; }</style>",
1617
activatedByChanged: function(activatedBy) {
1718
Survey.JsonObject.metaData.addClass("signaturepad", [], null, "empty");
1819
Survey.JsonObject.metaData.addProperties("signaturepad", [
20+
{ name: "allowClear:boolean", default: true },
1921
{ name: "width:number", default: 300 },
2022
{ name: "height:number", default: 200 }
2123
]);
2224
},
2325
afterRender: function(question, el) {
2426
var rootWidget = this;
25-
var canvas = document.createElement("canvas");
27+
var canvas = el.children[0].children[0];
2628
canvas.width = question.width;
2729
canvas.height = question.height;
28-
el.appendChild(canvas);
2930
var signaturePad = new SignaturePad(canvas);
3031
if (question.isReadOnly) {
3132
signaturePad.off();
@@ -36,11 +37,19 @@ function init(Survey) {
3637
question.value = data;
3738
};
3839
var updateValueHandler = function() {
40+
//signaturePad.clear();
3941
signaturePad.fromDataURL(question.value);
4042
};
4143
question.valueChangedCallback = updateValueHandler;
4244
updateValueHandler();
4345
question.signaturePad = signaturePad;
46+
if (question.allowClear) {
47+
el.children[1].children[0].onclick = function() {
48+
signaturePad.clear();
49+
};
50+
} else {
51+
el.children[1].children[0].remove();
52+
}
4453
},
4554
willUnmount: function(question, el) {
4655
if (question.signaturePad) {

0 commit comments

Comments
 (0)