Smooth Signatures
Open in new window

Survey.Survey.cssType = "bootstrap";
Survey.defaultBootstrapCss.navigationButton = "btn btn-green";

Survey.JsonObject.metaData.addProperty("text", {name: "renderAs", default: "standard", choices: ["standard", "signature_pad"]});

window.survey = new Survey.Model({ questions: [
 { type: "text", renderAs: "signature_pad", name: "sign", title: "Please enter your signature"}
]});
survey.onComplete.add(function(result) {
	document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(result.data);
});


var widget = {
    name: "signature_pad",
    htmlTemplate: "<canvas class='signature'></canvas>",
    isFit : function(question) { return question["renderAs"] === 'signature_pad'; },
    afterRender: function(question, el) {

        var el = el.querySelector("canvas");

        var me = this;
        me.signaturePad = new SignaturePad(el);
        me.signaturePad.penColor = "#1ab394";
        
        me.signaturePad.onEnd = function() {
          var data = me.signaturePad.toDataURL();
          question.value = data;
        }
    }

    ,
    willUnmount: function(question, el) {
        this.signaturePad.off();
    } 

}
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget);
survey.data = { countries: "Andorra" };


$("#surveyElement").Survey({
    model: survey
});




<!DOCTYPE html>
<html>

<head>
    <title>Welcome to JQuery</title>
    <script src="https://unpkg.com/jquery"></script>
    
    <script src="https://surveyjs.azureedge.net/0.12.19/survey.jquery.js"></script>
    
    
    <script src="https://unpkg.com/signature_pad@2.2.0/dist/signature_pad.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div id="surveyElement"></div>
    <div id="surveyResult"></div>
    <script src="./index.js"></script>
</body>

</html>

.btn-green {
  background-color: #1ab394;
  color: #fff;
  border-radius: 3px;
}

.btn-green:hover, .btn-green:focus {
    background-color: #18a689;
    color: #fff;
}

.panel-footer {
    text-align: right;
    background-color: #fff;
}

.signature {
  border: 1px solid #000;
}