Skip to content

Commit

Permalink
Composite Component - The setValueIf and setValueExpression do not wo…
Browse files Browse the repository at this point in the history
…rk for inner questions fix #7888 (#7892)
  • Loading branch information
andrewtelnov authored Feb 22, 2024
1 parent 5719c2a commit 8d34a9b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,14 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
this.setNewValueIntoQuestion(name, newValue);
super.setValue(name, newValue, locNotification, allowNotifyValueChanged);
this.settingNewValue = false;
this.runPanelTriggers(QuestionCompositeModel.ItemVariableName + "." + name, newValue);
}
private runPanelTriggers(name: string, value: any): void {
if(!!this.contentPanel) {
this.contentPanel.questions.forEach(q => {
q.runTriggers(name, value);
});
}
}
getFilteredValues(): any {
const values = !!this.data ? this.data.getFilteredValues() : {};
Expand Down
32 changes: 32 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,38 @@ QUnit.test("Composite: with expression", function (assert) {

ComponentCollection.Instance.clear();
});
QUnit.test("Composite: with setValueIf & setValueExpression, bug#7888", function (assert) {
const json = {
name: "comp1",
elementsJSON: [
{
"type": "text",
"name": "q1"
},
{
"type": "text",
"name": "q2",
"enableIf": "{composite.q1} notempty",
"setValueIf": "{composite.q1} notempty",
"setValueExpression": "{composite.q1} + {composite.q1}"
}
],
};
ComponentCollection.Instance.add(json);
const survey = new SurveyModel({ elements: [{ type: "comp1", name: "question1" }] });
const q = <QuestionCompositeModel>survey.getAllQuestions()[0];
const q1 = q.contentPanel.getQuestionByName("q1");
const q2 = q.contentPanel.getQuestionByName("q2");
assert.equal(q2.isEmpty(), true, "#1");
q1.value = 1;
assert.equal(q2.value, 2, "#2");
q1.value = 3;
assert.equal(q2.value, 6, "#3");
q1.clearValue();
assert.equal(q2.value, 6, "#4");

ComponentCollection.Instance.clear();
});
QUnit.test("Composite: check valueToData and valueFromData callbacks", function (assert) {
const json = {
name: "test",
Expand Down

0 comments on commit 8d34a9b

Please sign in to comment.