[FIX] survey: single line input on 'enter' key

Steps to reproduce
===================
1. Create single-line questions like numbers and single-line text.
2. Test the survey.
3. Press the 'enter' key on a single line input.
->The form reloads and does not submit.

Technical
==========
With commit https://github.com/odoo/odoo/commit/7109f480ec27e929a43c4bae78912bad42458e90, a next button is added before the submit button,
so when you press enter on single-line questions the first button of the
form is clicked which refreshes the page without any action.
Ref-https://github.com/odoo/odoo/blob/66b4e080e29551d1c74cdc4b3d9ccba92ce81dd1/addons/survey/static/src/js/survey_form.js#L116

After this commit
=================
We can submit the form with the 'enter' key from single-line input.

Task-3650231

closes odoo/odoo#149003

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Mayurrajsinh Rathod
2024-02-15 11:10:05 +00:00
parent 56666f8f78
commit 20ec8ac969
2 changed files with 4 additions and 3 deletions
@@ -1141,6 +1141,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa
// Make the form completely readonly
const form = document.querySelector('form');
form.querySelectorAll('input, textarea, label, td')?.forEach(node => {
node.blur();
node.classList.add("pe-none");
});
// Replace the Submit button by a Next button
+3 -3
View File
@@ -192,8 +192,8 @@
</t>
<div class="text-center mt16 mb256">
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<button type="submit" value="finish" class="btn btn-secondary disabled">Submit</button>
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<span class="fw-bold text-muted ms-2 d-none d-md-inline">
<span id="enter-tooltip">or press Enter</span>
</span>
@@ -213,12 +213,12 @@
<div class="col-12 text-center mt16">
<t t-set="submit_value" t-value="'finish' if survey_last or answer.is_session_answer else 'next_skipped'
if answer.survey_first_submitted and skipped_questions.page_id and page in skipped_questions.page_id else 'next'"/>
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<button type="submit" t-att-value="submit_value" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} disabled">
<t t-if="submit_value == 'finish'">Submit</t>
<t t-elif="submit_value == 'next_skipped'">Next Skipped</t>
<t t-else="">Continue</t>
</button>
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<span class="fw-bold text-muted ms-2 d-none d-md-inline" id="enter-tooltip"> or press Enter</span>
</div>
</div>
@@ -253,12 +253,12 @@
<div class="col-12 text-center mt16">
<t t-set="submit_value" t-value="'finish' if survey_last or answer.is_session_answer else
'next_skipped' if answer.survey_first_submitted and skipped_questions and question in skipped_questions else 'next'"/>
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<button type="submit" t-att-value="submit_value" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} disabled">
<t t-if="submit_value == 'finish'">Submit</t>
<t t-elif="submit_value == 'next_skipped'">Next Skipped</t>
<t t-else="">Continue</t>
</button>
<button id="next_page" t-attf-class="btn #{'btn-secondary' if survey_last else 'btn-primary'} d-none">Next</button>
<span class="fw-bold text-muted ms-2 d-none d-md-inline">
<span id="enter-tooltip">or press Enter</span>
</span>