diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index 65df4ef3b7b..0d6e2aa341e 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -80,33 +80,37 @@ $(document).ready(function () { // Pre-filling of the form with previous answers function prefill(){ - var prefill_def = $.ajax(prefill_controller, {dataType: "json"}) - .done(function(json_data){ - _.each(json_data, function(value, key){ - the_form.find(".form-control[name=" + key + "]").val(value); - the_form.find("input[name^=" + key + "]").each(function(){ - $(this).val(value); + if (! _.isUndefined(prefill_controller)) { + var prefill_def = $.ajax(prefill_controller, {dataType: "json"}) + .done(function(json_data){ + _.each(json_data, function(value, key){ + the_form.find(".form-control[name=" + key + "]").val(value); + the_form.find("input[name^=" + key + "]").each(function(){ + $(this).val(value); + }); }); + }) + .fail(function(){ + console.warn("[survey] Unable to load prefill data"); }); - }) - .fail(function(){ - console.warn("[survey] Unable to load prefill data"); - }); - return prefill_def; + return prefill_def; + } } // Display score if quiz correction mode function display_scores(){ - var score_def = $.ajax(scores_controller, {dataType: "json"}) - .done(function(json_data){ - _.each(json_data, function(value, key){ - the_form.find("span[data-score-question=" + key + "]").text("Your score: " + value); + if (! _.isUndefined(scores_controller)) { + var score_def = $.ajax(scores_controller, {dataType: "json"}) + .done(function(json_data){ + _.each(json_data, function(value, key){ + the_form.find("span[data-score-question=" + key + "]").text("Your score: " + value); + }); + }) + .fail(function(){ + console.warn("[survey] Unable to load score data"); }); - }) - .fail(function(){ - console.warn("[survey] Unable to load score data"); - }); - return score_def; + return score_def; + } } // Parameters for form submission