Skip to content

Commit

Permalink
#7289 Signature Pad - Introduce an option to upload a signature to a …
Browse files Browse the repository at this point in the history
…specified storage

Fixes #7289
  • Loading branch information
novikov82 committed Nov 27, 2023
1 parent 45fdeff commit ffd24ff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/question_signaturepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ export class QuestionSignaturePadModel extends QuestionFileModelBase {

private fromUrl(url: string) {
const img = document.createElement("img");
img.crossOrigin = "anonymous";
img.src = url;
img.onload = ()=>{
const ctx = this.canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = this.canvas.toDataURL(this.getFormat());
this.fromDataURL(dataURL);
this.fromDataUrl(dataURL);
};
}
private refreshCanvas() {
Expand All @@ -118,7 +120,7 @@ export class QuestionSignaturePadModel extends QuestionFileModelBase {
this.signaturePad.clear();
} else {
if(this.storeDataAsText) {
this.fromDataURL(this.value);
this.fromDataUrl(this.value);
} else {
this.fromUrl(this.value);
}
Expand Down Expand Up @@ -344,7 +346,7 @@ export class QuestionSignaturePadModel extends QuestionFileModelBase {
if (!this.storeDataAsText && this.valueWasChangedFromLastUpload) {
this.valueWasChangedFromLastUpload = false;
this.canvas.toBlob((blob: Blob) => {
this.uploadFiles([new File([blob], this.name + correctFormatData(this.dataFormat), { type: this.dataFormat })]);
this.uploadFiles([new File([blob], this.name + "." + correctFormatData(this.dataFormat), { type: this.getFormat() })]);
}, this.dataFormat);
}
}
Expand Down Expand Up @@ -449,6 +451,9 @@ Serializer.addClass(
},
{ name: "defaultValue", visible: false },
{ name: "correctAnswer", visible: false },
{ name: "storeDataAsText:boolean", default: true },
{ name: "waitForUpload:boolean", default: false },

],
function () {
return new QuestionSignaturePadModel("");
Expand Down

0 comments on commit ffd24ff

Please sign in to comment.