From be5e86f464a98bc83acd2d09a7caf8089e2f8fad Mon Sep 17 00:00:00 2001 From: David Beguin Date: Fri, 24 Jan 2020 09:24:26 +0000 Subject: [PATCH] [FIX] survey: fix first input autofocus Before this commit, the survey form widget was focusing on the first text input found on the page, even if this input was not the first question. After this commit, the survey form widget focus only on first text input if that input is the first question on the page. Triggered by task ID 1972640 (live sessions on survey) PR #44205 Signed-off-by: Thibault Delavallee (tde) --- addons/survey/static/src/js/survey_form.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index 09cf0a21d9f..6c51b0e2d8c 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -685,9 +685,12 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ * without having to manually get the focus (only if the input has the right type - can write something inside -) */ _focusOnFirstInput: function () { - var $inputs = this.$("input[type='text'],input[type='number'],textarea").not('.o_survey_comment'); - if ($inputs.length > 0) { - $inputs.first().focus(); + var $firstTextInput = this.$('.js_question-wrapper').first() // Take first question + .find("input[type='text'],input[type='number'],textarea") // get 'text' inputs + .filter('.form-control') // needed for the auto-resize + .not('.o_survey_comment'); // remove inputs for comments that does not count as answers + if ($firstTextInput.length > 0) { + $firstTextInput.focus(); } },