Skip to content

Commit

Permalink
Custom expression property is not working on adding it into choices i…
Browse files Browse the repository at this point in the history
…tems fix #8641 (#8642)
  • Loading branch information
andrewtelnov authored Aug 2, 2024
1 parent 496ad97 commit 4019e5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionCheckboxModel>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");
});

0 comments on commit 4019e5b

Please sign in to comment.