From 4019e5bb1ed8979b7a330302a6ea01294f534d40 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 2 Aug 2024 10:19:13 +0300 Subject: [PATCH] Custom expression property is not working on adding it into choices items fix #8641 (#8642) --- src/question_baseselect.ts | 3 +++ tests/question_baseselecttests.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index 8e5d032000..fe0b47e80a 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -358,6 +358,9 @@ export class QuestionSelectBase extends Question { super.runCondition(values, properties); this.runItemsEnableCondition(values, properties); this.runItemsCondition(values, properties); + this.choices.forEach(item => { + item.runConditionCore(values, properties); + }); } protected isTextValue(): boolean { return true; //for comments and others diff --git a/tests/question_baseselecttests.ts b/tests/question_baseselecttests.ts index 9a2c335e02..95aece61ec 100644 --- a/tests/question_baseselecttests.ts +++ b/tests/question_baseselecttests.ts @@ -2186,3 +2186,30 @@ QUnit.test("Unselect none item, bug#8438", (assert) => { q.clickItemHandler(q.noneItem, true); assert.deepEqual(q.value, ["none"], "#3"); }); + +QUnit.test("Add condition custom property", function (assert) { + Serializer.addProperty("itemvalue", { + name: "customExp:expression", + onExecuteExpression: (obj, res) => { + obj.setPropertyValue("customVal", res); + } + }); + const survey = new SurveyModel({ + elements: [ + { + type: "checkbox", + name: "q1", + choices: [1, 2, { value: 3, customExp: "{q1.length}" }] + } + ] + }); + const q = survey.getQuestionByName("q1"); + const item3 = q.choices[2]; + assert.equal(item3.getPropertyValue("customVal"), 0, "#1"); + q.value = [1, 2, 3]; + assert.equal(item3.getPropertyValue("customVal"), 3, "#2"); + q.value = [2]; + assert.equal(item3.getPropertyValue("customVal"), 1, "#3"); + + Serializer.removeProperty("itemvalue", "customExp"); +});