question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose underlying events from signature_pad

See original GitHub issue

Exposing the underlying events of signature_pad would be very useful as it allows to react to signature inputs instead of polling the data of signature_pad.

This would allow a pattern like:

const [signature, setSignature] = useState("")
...
<SignaturePad ... onEnd={x=> setSignature(x.toDataURL())} />

or add the events to the options, as they are “low level” events, like

<SignaturePad ... options={{
    onEnd(x) { setSignature(x.toDataURL()) }
}} />

This allows the rest of the code to react to the value of signature easily (e.g. disable the save button and display a message if no signation was made…).


Or alternatively expose the whole underying signature_pad object.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesRobertWisemancommented, Jan 20, 2022

You are right. The following will work:

  const [signaturePad, setSignaturePad] = React.useState<SignaturePad>();

  const signaturePadRef = React.useCallback((signaturePad: SignaturePad) => {
    setSignaturePad(signaturePad);
  }, []);

  const onStrokeEnd = () => {
    setSignature(signaturePad.toData());
  }

  React.useEffect(() => {
    if (signaturePad) {
      signaturePad.instance.addEventListener('endStroke', onStrokeEnd)
    }
    //cleanup event listener
    () => signaturePad.instance.removeEventListener('endStroke', onStrokeEnd);
  }, [signaturePad]);

1reaction
toburgercommented, Dec 16, 2021

If someone is having trouble accessing the underlying instance and registering the event with the hooks API here is the working TS code:

  const [signaturePad, setSignaturePad] = React.useState<SignaturePad>();
  const signaturePadRef = React.useCallback((signaturePad: SignaturePad) => {
    setSignaturePad(signaturePad);
  }, []);
  React.useEffect(() => {
    if (signaturePad) {
      signaturePad.instance.onEnd = () => {
        setSignature(signaturePad.instance.toDataURL());
      };
    }
  }, [signaturePad]);

More info of why this is quite tricky can be found here or here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exposing the SignaturePad Events in PDFViewer - Syncfusion
Is there a way to access the event that is triggered when the user presses "Done" on the signature pad dialog in the...
Read more >
Signature pad for HR - Product Documentation | ServiceNow
The HR Service Delivery application uses signature pad with onboarding documents like offer letters, background check approval, company policy acknowledgements, ...
Read more >
Draw and Save Signatures in Xamarin.Forms applications
The SignaturePad exposes StrokeStarted event to determine when a new stroke is started and StrokeCompleted event when the stroke is ...
Read more >
Using the Signature Pad jQuery Plugin with SharePoint ...
Signature Pad : A jQuery plugin for assisting in the creation of an HTML5 canvas based signature pad. Records the drawn signature in...
Read more >
Need help with custom form control - validation and ngModel
I'm trying to build a form with a signature pad as one of the items. ... The biggest problem you have is that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found