You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
andrewtelnov
changed the title
Validate survey question results on server via Ajax requests
Add ability to validate survey question results on server via Ajax requests
Nov 28, 2016
onServerValidateQuestions callback is added into survey class. Here is the example of using:
<script>
var json = {
questions: [{ type: "text", name: "country" }]
};
var survey = new Survey.Survey(json);
//assign call to onServerValidateQuestions callback
survey.onServerValidateQuestions = function (survey, options) {
//options.data contains the data for the current page.
var countryName = options.data["country"];
//If the question is empty then do nothing
if (!countryName) options.complete();
//call the ajax method
$.ajax({
url: "http://services.groupkt.com/country/get/all"
}).then(function (data) {
var found = false;
var countries = data.RestResponse.result;
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 is unknown.";
//tell survey that we are done with the server validation
options.complete();
});
}
survey.render("dxsurvey");
</script>
Create an API that will allow easily to call server code to validate question results.
The text was updated successfully, but these errors were encountered: