[FIX] survey: fix "multiple choices one answer" keyboard related bug

Bug
===
1. Create a survey with the option "One page per question"
2. Create a "Multiple choice - only one value" question
3. Go to the survey, select a question
4. With the keyboard unselect the question
5. Submit

You will be able to submit your answer even if nothing seems to be
selected.

We also want to be able to unselect answers with the keyboard.

Technical
=========
The event "onchange" can be triggered for the radio button even if there
was no change. The reason is because we always "write true" on the radio
(even if it was already check) and we always trigger manually the event
"onchange".

Task-2345463

closes odoo/odoo#58771

X-original-commit: ad2b4fe9c1ad0f09df33daab3a0784d2d5392fbd
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
std-odoo
2020-09-29 09:31:30 +00:00
committed by Debauche Stéphane
parent 01d35051c0
commit 8bba8852b8
+1 -5
View File
@@ -117,11 +117,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
&& letter.match(/[a-z]/i)) {
var $choiceInput = this.$(`input[data-selection-key=${letter}]`);
if ($choiceInput.length === 1) {
if ($choiceInput.attr('type') === 'radio') {
$choiceInput.prop("checked", true).trigger('change');
} else {
$choiceInput.prop("checked", !$choiceInput.prop("checked")).trigger('change');
}
$choiceInput.prop("checked", !$choiceInput.prop("checked")).trigger('change');
// Avoid selection key to be typed into the textbox if 'other' is selected by key
event.preventDefault();