-
Notifications
You must be signed in to change notification settings - Fork 804
Editors Signature Editor using SignaturePad
Victor Tomaili edited this page May 3, 2021
·
1 revision
(by Wesley Huang)
- Open a command prompt in the project folder, and run
npm install --save signature_pad
- In ScriptBundles.json, add
"~/node_modules/signature_pad/dist/signature_pad.umd.js"
- Create a TypeScript file called
SignatureEditor.ts
namespace YourProjectName {
@Serenity.Decorators.element('<div />')
@Serenity.Decorators.registerEditor([Serenity.IGetEditValue, Serenity.ISetEditValue])
export class SignatureEditor extends Serenity.Widget<SignatureEditorOptions>
implements Serenity.IGetEditValue, Serenity.ISetEditValue
{
private signaturePad: any;
constructor(div: JQuery, options: SignatureEditorOptions) {
super(div, options);
let canvas = $('<canvas />').attr('id', 'sign_' + this.uniqueName);
this.element.append(canvas);
this.signaturePad = new SignaturePad(canvas[0]);
let clearButton = $('<button />').attr('id', 'clearsign_' + this.uniqueName).html('<i class="fa fa-eraser"></i>');
clearButton.on('click', (e) => {
e.preventDefault();
this.signaturePad.clear();
});
this.element.append(clearButton);
}
public get value(): string {
return this.get_value();
}
protected get_value(): string {
return this.signaturePad.toDataURL();
}
public set value(value: string) {
this.set_value(value);
}
protected set_value(value: string): void {
this.signaturePad.fromDataURL(value);
}
setEditValue(source: any, property: Serenity.PropertyItem): void {
this.value = source[property.name];
}
getEditValue(property: Serenity.PropertyItem, target: any): void {
target[property.name] = this.value;
}
}
export interface SignatureEditorOptions {
}
}
BTW, Does any one know how to get rid of red tilde under SignaturePad? Please let me know. Thanks
- run T4 template.
Usage
- Add a column in table with data type NVARCHAR(MAX)
- Add the column in your
Row.cs
file - Add the column in your
Form.cs
file as below (assume your column is called 'Signature')
[SignatureEditor]
public String Signature { get; set; }
That's all.
Copyright © Serenity Platform 2017-present. All rights reserved.
Documentation | Serene Template | Live Demo | Premium Support | Issues | Discussions