From f91462c1fa405e450bc2f0d8509c7c89ab701ecc Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Mon, 22 Apr 2024 17:37:09 +0300 Subject: [PATCH] MaxSelectedChoices stop updating Disabled class for selectbase (problem with v1.9.139) fix #8159 --- src/question_baseselect.ts | 2 +- tests/question_baseselecttests.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index fd96c4b69b..56de203e51 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -1723,7 +1723,7 @@ export class QuestionSelectBase extends Question { options.isNone = isNone; return builder - .append(this.cssClasses.itemDisabled, this.isDisabledStyle) + .append(this.cssClasses.itemDisabled, isDisabled || this.isDisabledStyle) .append(this.cssClasses.itemReadOnly, this.isReadOnlyStyle) .append(this.cssClasses.itemPreview, this.isPreviewStyle) .append(this.cssClasses.itemChecked, isChecked) diff --git a/tests/question_baseselecttests.ts b/tests/question_baseselecttests.ts index 262125147c..ca9dd3df0c 100644 --- a/tests/question_baseselecttests.ts +++ b/tests/question_baseselecttests.ts @@ -315,6 +315,29 @@ QUnit.test("check allowhover class in design mode", (assert) => { survey.setDesignMode(true); assert.ok(q1.getItemClass(item).indexOf("sv_q_checkbox_hover") == -1); }); +QUnit.test("maxSelectedChoices & getItemClass, bug#8159", (assert) => { + var json = { + questions: [ + { + type: "checkbox", + name: "q1", + choices: ["Item1", "Item2", "Item3"], + maxSelectedChoices: 2 + }, + ], + }; + const survey = new SurveyModel(json); + const q1 = survey.getQuestionByName("q1"); + const disableStyle = "sv_q_disable"; + q1.cssClasses.itemDisabled = disableStyle; + q1.renderedValue = ["Item1", "Item3"]; + assert.ok(q1.visibleChoices[0].enabled, "Item1 enabled #2"); + assert.notOk(q1.getItemClass(q1.visibleChoices[0]).indexOf(disableStyle) >= 0, "Item1 #1"); + assert.notOk(q1.visibleChoices[1].enabled, "Item2 enabled #2"); + assert.ok(q1.getItemClass(q1.visibleChoices[1]).indexOf(disableStyle) >= 0, "Item2 #2"); + assert.notOk(q1.getItemClass(q1.visibleChoices[2]).indexOf(disableStyle) >= 0, "Item3 #3"); +}); + QUnit.test("check item value type", (assert) => { const survey = new SurveyModel({ questions: [