From f92c5dad9346bd2caeeb56bff156b2da31e64383 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Wed, 30 Aug 2023 09:32:37 +0300 Subject: [PATCH] Fixed https://github.com/surveyjs/private-tasks/issues/274 - Boolean question's editing issue (#6793) Co-authored-by: tsv2013 --- src/question_boolean.ts | 5 ++-- tests/questionBooleanTests.ts | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/question_boolean.ts b/src/question_boolean.ts index c76fd90a33..aca32799dd 100644 --- a/src/question_boolean.ts +++ b/src/question_boolean.ts @@ -45,7 +45,7 @@ export class QuestionBooleanModel extends Question { return this.value == this.getValueTrue(); } public set booleanValue(val: any) { - if (this.isReadOnly) { + if (this.isReadOnly || this.isDesignMode) { return; } this.setBooleanValue(val); @@ -258,9 +258,8 @@ export class QuestionBooleanModel extends Question { } public onKeyDownCore(event: any): boolean { if (event.key === "ArrowLeft" || event.key === "ArrowRight") { - preventDefaults(event); + event.stopPropagation(); this.calculateBooleanValueByEvent(event, event.key === "ArrowRight"); - return; } return true; } diff --git a/tests/questionBooleanTests.ts b/tests/questionBooleanTests.ts index 615e8c84eb..78b8950b40 100644 --- a/tests/questionBooleanTests.ts +++ b/tests/questionBooleanTests.ts @@ -191,4 +191,50 @@ QUnit.test("Check boolean labelRenderedAriaID", function (assert) { question.titleLocation = "hidden"; assert.strictEqual(question.labelRenderedAriaID.indexOf("_ariaTitle") !== -1, true); +}); + +QUnit.test("Boolean shouldn't call preventDefault on key down", function (assert) { + var json = { + "elements": [ + { + "type": "boolean", + "name": "bool", + } + ] + }; + var survey = new SurveyModel(json); + var question = survey.getAllQuestions()[0]; + + let pdCount = 0; + let spCount = 0; + const event = { + key: "ArrowLeft", + target: document.createElement("div"), + preventDefault: () => { pdCount++; }, + stopPropagation: () => { spCount++; } + }; + question.onKeyDownCore(event); + assert.equal(pdCount, 0); + assert.equal(spCount, 1); +}); +QUnit.test("Boolean shouldn't set booleanValue in design time", function (assert) { + var json = { + "elements": [ + { + "type": "boolean", + "name": "bool", + } + ] + }; + var survey = new SurveyModel(json); + var question = survey.getAllQuestions()[0]; + + assert.equal(question.value, undefined); + + question.booleanValue = true; + assert.equal(question.value, true); + + survey.setDesignMode(true); + question.booleanValue = false; + assert.equal(question.value, true); }); \ No newline at end of file