2

I try implement custom widget follow guide https://surveyjs.io/Examples/Library/?id=custom-widget-select2-tagbox but not show image challenge of captcha

how can i implement captcha image challenge for surveyjs form?

Tom
  • 47
  • 6
  • Have you seen the code of the microphone widget which can be similar? - https://github.com/surveyjs/widgets/blob/master/src/microphone.js – TSV Nov 01 '19 at 08:04

1 Answers1

0

i find the way:

html:

{
  type: "html",
  name: "info",
  html: "<div id='g-recaptcha'></div> <div class='form-group g-recaptcha' data-callback='verifyCaptcha' data-sitekey='" + recaptchaClientKey + "'></div>"
}

ts, js

survey.onCompleting.add(function (sender, options) {
    debugger;
    var response = grecaptcha.getResponse();
    if (response.length == 0) {
        document.getElementById('g-recaptcha').innerHTML =
            '<span class="form-group text-danger validation-summary-errors" data-valmsg-summary="true"><ul><li>Google reCAPTCHA validation failed</li></ul ></span >';
        options.allowComplete = false;
    } else {
        options.allowComplete = true;
    }
});

@section Scripts{
    <script type="text/javascript" src="~/js/signup/survey_config.js"></script>
    <script src='https://www.google.com/recaptcha/api.js'></script>
    <script>
        function verifyCaptcha() {
            document.getElementById('g-recaptcha').innerHTML = '';
        }
    </script>
}
Tom
  • 47
  • 6