From bcec68f783191fcd14b97450eebb067ed45a1ad4 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Wed, 19 Jun 2024 10:26:56 +0300 Subject: [PATCH] "None" choice in checkbox question is not deselected on clicking on it when it is selected fix #8438 --- src/question_checkbox.ts | 2 +- tests/question_baseselecttests.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/question_checkbox.ts b/src/question_checkbox.ts index 2e5cc33393..4abb7e541c 100644 --- a/src/question_checkbox.ts +++ b/src/question_checkbox.ts @@ -167,7 +167,7 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase { } } else { if(this.isNoneItem(item)) { - this.renderedValue = [item.value]; + this.renderedValue = checked ? [item.value] : []; } else { const newValue: Array = [].concat(this.renderedValue || []); const index = newValue.indexOf(item.value); diff --git a/tests/question_baseselecttests.ts b/tests/question_baseselecttests.ts index da661d9d57..65a02d0b3f 100644 --- a/tests/question_baseselecttests.ts +++ b/tests/question_baseselecttests.ts @@ -2160,3 +2160,22 @@ QUnit.test("valuePropertyName & complete trigger, bug#8434", (assert) => { q.renderedValue = ["none"]; assert.equal(survey.calcIsCompleteButtonVisible(), true, "#4"); }); +QUnit.test("Unselect none item, bug#8438", (assert) => { + const survey = new SurveyModel({ + "elements": [ + { + "type": "checkbox", + "name": "q1", + "choices": [1, 2, 3], + "showNoneItem": true + } + ] + }); + const q = survey.getQuestionByName("q1"); + q.clickItemHandler(q.noneItem, true); + assert.deepEqual(q.value, ["none"], "#1"); + q.clickItemHandler(q.noneItem, false); + assert.equal(q.isEmpty(), true, "#2"); + q.clickItemHandler(q.noneItem, true); + assert.deepEqual(q.value, ["none"], "#3"); +});