From f2e2b6260b3436cf894a9ea8343fb888844ed632 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Thu, 22 Nov 2018 15:31:36 +0000 Subject: [PATCH] [IMP] survey : scroll up to first survey validation error - Change the default value of the Validation Error message on the Date : "The answer you entered is not valid." - If long page, click on next and one error, the page should go up to allow the visitor to see where the error is. Task ID : 1911291 Closes PR #29054 --- addons/survey/models/survey_question.py | 2 +- addons/survey/static/src/js/survey.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/survey/models/survey_question.py b/addons/survey/models/survey_question.py index 5014c96e017..56647bb2830 100644 --- a/addons/survey/models/survey_question.py +++ b/addons/survey/models/survey_question.py @@ -77,7 +77,7 @@ class SurveyQuestion(models.Model): validation_max_float_value = fields.Float('Maximum value') validation_min_date = fields.Date('Minimum Date') validation_max_date = fields.Date('Maximum Date') - validation_error_msg = fields.Char('Validation Error message', translate=True, default=lambda self: _("The answer you entered has an invalid format.")) + validation_error_msg = fields.Char('Validation Error message', translate=True, default=lambda self: _("The answer you entered is not valid.")) # Constraints on number of answers (matrices) constr_mandatory = fields.Boolean('Mandatory Answer') constr_error_msg = fields.Char('Error message', translate=True, default=lambda self: _("This question requires an answer.")) diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index 42a98752ab6..2b9094e37b1 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -145,6 +145,11 @@ if(!the_form.length) { if(_.has(response, 'errors')){ // some questions have errors _.each(_.keys(response.errors), function(key){ $("#" + key + '>.js_errzone').append('

' + response.errors[key] + '

').show(); + if (_.keys(response.errors)[_.keys(response.errors).length - 1] === key) { + $('html, body').animate({ + scrollTop: $('.js_errzone:visible:first').closest('.js_question-wrapper').offset().top - $('.o_main_navbar').height() + }, 500); + } }); return false; }