Cart Buy Licenses Contact Integrate into App Docs Support Login/Register
v 1.8.68
v 1.8.68
Overview Examples Docs Source Download

Server Validators

Example of using onServerValidateQuestions callback


//assign call to onServerValidateQuestions callback
function surveyValidateQuestion(survey, options) {
    // contains the data for the current page.
    var countryName =["country"];
    //If the question is empty then do nothing
    if (!countryName) {
    //call the ajax method
        url: ""
    }).then(function (data) {
        var found = false;
        var countries = data;
        for (var i = 0; i < countries.length; i++) {
            if (countries[i].name == countryName) {
                found = true; break;
        //if the country is unknown, add the error
        if (!found) options.errors["country"] = "The country name '" + countryName +"' is not in this list:";
        //tell survey that we are done with the server validation
                var json = {
    questions: [{ type: "text", name: "country", title: "Type a country:" }]

                window.survey = new Survey.Model(json);
            survey.onComplete.add(function(sender) {
            document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(, null, 3);
            <Survey.Survey model={survey}  />, document.getElementById("surveyElement"));
<!DOCTYPE html>
<html lang="en">
    <title>Example of using onServerValidateQuestions callback, Reactjs Survey Library Example</title>

<meta name="viewport" content="width=device-width" />
    <script src=""></script>
        <script src=""></script>
        <script src=""></script>
        <script src=""></script>
        <script src=""></script>
    <script src="/DevBuilds/survey-react/survey.react.min.js"></script>
    <link href="/DevBuilds/survey-core/modern.min.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

            <div id="surveyElement" style="display:inline-block;width:100%;">
    <div id="surveyResult"></div>

<script type="text/babel" src="./index.js"></script>