Replies: 5 comments
-
Can you link to your code so we can help? |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the quick reply. I finally got there using the "afterUpdateStroke" event, so maybe it's a case of me not quite understanding the meanings of those event names. This example works, and I can detect changes in the signature from the page the components are embedded in. If I change the handler to "endStroke" the event is never dispatched. morf-signature.mjs:
Test oage:
|
Beta Was this translation helpful? Give feedback.
-
Figured it out. I used the "afterUpdateStroke" event to dispatch a Custom Event, 'signatureUpdate' which I can pick up the the parent page. |
Beta Was this translation helpful? Give feedback.
-
This seems to work with endStroke <!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
signature-canvas {
width: 100vw;
height: 100vh;
display: block;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/signature_pad.umd.min.js"></script>
<script>
class SignatureCanvas extends HTMLElement {
constructor() {
super();
this.canvas = document.createElement('canvas');
this.canvas.style.width = "100vw";
this.canvas.style.height = "100vh";
this.attachShadow({ mode: "open" });
this.shadowRoot.append(this.canvas);
}
_handleBeginStroke() {
console.log('beginStroke');
}
_handleEndStroke () {
console.log('endStroke');
}
connectedCallback(){
console.log('connectedCallback');
this.sigCanvas = new SignaturePad(this.canvas, this.options);
this.sigCanvas.addEventListener("endStroke", this._handleEndStroke );
this.sigCanvas.addEventListener("beginStroke", this._handleBeginStroke );
const ratio = Math.max(window.devicePixelRatio || 1, 1);
this.canvas.width = this.canvas.offsetWidth * ratio;
this.canvas.height = this.canvas.offsetHeight * ratio;
this.canvas.getContext("2d").scale(ratio, ratio);
}
}
customElements.define("signature-canvas", SignatureCanvas);
</script>
</head>
<body>
<signature-canvas></signature-canvas>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
-
Ahhh got it.... version. I was still running 4.00... as soon as I switched to 5.02 the endStroke worked. I then noticed that toDataURL() stopped working :(. I'll stick with 4.00 for now because it's stable, but thanks for the reply. |
Beta Was this translation helpful? Give feedback.
-
Hi there, I've been using this library for a few years now, across numerous different projects... I love it!
This week I finally decided to roll it into a web component and while that is all working perfectly, I can never get the "endStroke" event to fire. The "beginStroke" event works as expected. I tried removing / re-binding them with .off() and .on(), but no joy.
Has anybody got it to work in a web component? Any tricks or tips? My next move is to pull apart the source of the React signature_pad, but i though I'd ask the question first. :)
Beta Was this translation helpful? Give feedback.
All reactions