[FIX] survey: prevent unwanted submission of one-page survey

Previously, In "one_page & page_per_section" survey, pressing Enter would
submit the survey, leading to confusion and accidental submissions, as users
might press Enter intending to navigate through questions.

With this commit, Now, requiring "Ctrl + Enter" to submit, ensures clarity in
survey submission, reducing the chance of accidental submission.

task-3707763

closes odoo/odoo#152850

Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Earth Patel
2024-03-06 11:02:08 +00:00
parent 4543a530c9
commit da9d6b42f9
3 changed files with 20 additions and 8 deletions
+3 -3
View File
@@ -414,7 +414,7 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:survey.survey_fill_form_in_progress
msgid ""
"<span class=\"fw-bold text-muted ms-2 d-none d-md-inline\" id=\"enter-"
"tooltip\"> or press Enter</span>"
"tooltip\"> or press CTRL+Enter</span>"
msgstr ""
#. module: survey
@@ -429,8 +429,8 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:survey.survey_fill_form_in_progress
msgid ""
"<span class=\"fw-bold text-muted ms-2 d-none d-md-inline\">\n"
" <span id=\"enter-tooltip\">or press Enter</span>\n"
" </span>"
" <span id=\"enter-tooltip\">or press CTRL+Enter</span>\n"
" </span>"
msgstr ""
#. module: survey
+13 -1
View File
@@ -109,6 +109,15 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa
_onKeyDown: function (event) {
var self = this;
if (['one_page', 'page_per_section'].includes(self.options.questionsLayout) && !self.options.isStartScreen) {
if (this.$("input").is(":focus") && event.key === "Enter") {
event.preventDefault();
}
if (!(event.ctrlKey || event.metaKey) || event.key !== "Enter") {
return;
}
}
// If user is answering a text input, do not handle keydown
// CTRL+enter will force submission (meta key for Mac)
if ((this.$("textarea").is(":focus") || this.$('input').is(':focus')) &&
@@ -267,7 +276,10 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa
_updateEnterButtonText: function (event) {
const $target = event.target;
const isTextbox = event.type === "focusin" && $target.tagName.toLowerCase() === 'textarea';
const text = !isTextbox ? _t('or press Enter') : isMac ? _t("or press ⌘+Enter") : _t("or press CTRL+Enter");
let text = _t("or press Enter");
if (['one_page', 'page_per_section'].includes(this.options.questionsLayout) || isTextbox) {
text = isMac ? _t("or press ⌘+Enter") : _t("or press CTRL+Enter");
}
$('#enter-tooltip').text(text);
},
+4 -4
View File
@@ -194,9 +194,9 @@
<div class="text-center mt16 mb256">
<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>
<span class="fw-bold text-muted ms-2 d-none d-md-inline">
<span id="enter-tooltip">or press CTRL+Enter</span>
</span>
</div>
</t>
@@ -219,7 +219,7 @@
<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>
<span class="fw-bold text-muted ms-2 d-none d-md-inline" id="enter-tooltip"> or press CTRL+Enter</span>
</div>
</div>
</t>