3

I'm working with SignaturePad. (https://github.com/szimek/signature_pad)

According to the API, onBegin() is called at the start of a stroke, however it seems to only get called on page load

Example:

var pad = new SignaturePad (canvas, {
  backgroundColor: 'rgb(255,255,255)',
  velocityFilterWeight:0.4,
  onBegin: console.log('hello')
  //onBegin: startWritingTimer()
});

The above code logs 'hello' when the page is loaded, rather than at the start of each stroke. Have I misinterpreted the API?

Itchydon
  • 2,572
  • 6
  • 19
  • 33
dward
  • 31
  • 4

2 Answers2

4

This is how I did it in JQuery:

jQuery(document).ready(function($){

    var canvas = document.getElementById("signature");
    var signaturePad = new SignaturePad(canvas);

    $('#clear-signature').on('click', function(){
        signaturePad.clear();
    });

    $('#submit-signature').on('click', function(){
        submitSignature();
    });

    signaturePad.onBegin = function() {
        alert('just began!');
    };


    function submitSignature(){
        if(!signaturePad.isEmpty()){
            alert('not empty');
        }   
    }

});
SchonSauce
  • 71
  • 5
  • Welcome to StackOverflow. It's generally accepted that quality answers will include some explanation in addition to your code as it helps the original author with the issue. This is especially important when you are suggesting an alternate solution such as bringing jquery - you should explain why you made this choice. – Graham Feb 06 '18 at 04:31
0

I came across this as well. After a few attempts, this is how you can call it using your variable.

pad.onBegin = function(event) {
  console.log('pad.onBegin has been called.', event);
};
Airerr
  • 451
  • 4
  • 16