Skip to content

Commit

Permalink
Default Value Expression overrides the survey.data values with v1.9.1…
Browse files Browse the repository at this point in the history
…07 and newer fix #7423 (#7426)
  • Loading branch information
andrewtelnov committed Nov 28, 2023
1 parent bf99b84 commit 1749439
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ export class Question extends SurveyElement<Question>
this.updateValueFromSurveyCore(newValue, this.isTwoValueEquals(newValue, val));
});
} else {
this.updateValueFromSurveyCore(newValue, isEmpty);
this.updateValueFromSurveyCore(newValue, <any>this.data !== <any>this.getSurvey());
}
this.updateDependedQuestions();
this.updateIsAnswered();
Expand Down
46 changes: 46 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18268,3 +18268,49 @@ QUnit.test("Expression bug with complex path, #7396", function (assert) {
q2.value = { "16": 2 };
assert.equal(q3.isVisible, true, "visible #3");
});
QUnit.test("Do not run defaultValueExpression on survey.data, #7423", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "text",
name: "q1",
defaultValueExpression: "value1"
},
{
type: "text",
name: "q2",
defaultValueExpression: "value2"
},
{
type: "checkbox",
name: "q3",
choices: ["item1", "item2", "item3"],
defaultValueExpression: "['item1', 'item3']"
},
{
type: "dropdown",
name: "q4",
choices: ["item1", "item2", "item3"],
defaultValueExpression: "item2"
}
]
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
const q3 = survey.getQuestionByName("q3");
const q4 = survey.getQuestionByName("q4");
assert.equal(q1.value, "value1", "q1.value #1");
assert.equal(q2.value, "value2", "q2.value #1");
assert.deepEqual(q3.value, ["item1", "item3"], "q3.value #1");
assert.equal(q4.value, "item2", "q4.value #1");
survey.data = { q1: "val1" };
assert.equal(q1.value, "val1", "q1.value #2");
assert.notOk(q2.value, "q2.value #2");
assert.deepEqual(q3.value, [], "q3.value #2");
assert.notOk(q4.value, "q4.value #2");
q2.value = "val2";
assert.equal(q1.value, "val1", "q1.value #3");
assert.equal(q2.value, "val2", "q2.value #3");
assert.deepEqual(q3.value, [], "q3.value #3");
assert.notOk(q4.value, "q4.value #3");
});

0 comments on commit 1749439

Please sign in to comment.